From 5d558b35b6841de1b4d75b5eeb1144826a71fd5c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 4 Dec 2022 17:01:15 +0300 Subject: [PATCH] tweaks... Signed-off-by: Alex A. Naanou --- Promise.js | 28 +++++++++++++++------------- package.json | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Promise.js b/Promise.js index 20a2798..9cfea47 100644 --- a/Promise.js +++ b/Promise.js @@ -849,13 +849,16 @@ object.Constructor('SyncPromise', Promise, { // mode and thus set .value and possibly .error, soe there is no // need to check for .value... then: function(resolve, reject){ - if(this.hasOwnProperty('error')){ - return this.constructor.reject( - reject ? - reject(this.error) - : this.error) } - return this.constructor.resolve( - resolve(this.value)) }, + return this.hasOwnProperty('error') ? + this.constructor.reject( + reject ? + reject(this.error) + : this.error) } + : resolve ? + this.constructor.resolve( + resolve(this.value)) + // XXX should we return a copy??? + : this }, // NOTE: if func calls resolve(..) with a promise then this will return // that promise... @@ -895,10 +898,8 @@ object.Mixin('PromiseMixin', 'soft', { iter: IterablePromise, interactive: InteractivePromise, cooperative: CooperativePromise, - // XXX EXPEREMENTAL... sync: SyncPromise, - - // XXX need error support... + // XXX should this be implemented via SyncPromise??? awaitOrRun: function(data, func){ data = [...arguments] func = data.pop() @@ -943,11 +944,12 @@ object.Mixin('PromiseProtoMixin', 'soft', { as: ProxyPromise, iter: function(handler=undefined){ return IterablePromise(this, handler) }, - // XXX revise... - sync: function(){ + sync: function(error='throw'){ if(this instanceof SyncPromise){ if('error' in this){ - throw this.error } + if(typeof(error) != 'function'){ + throw this.error } + return error(this.error) } return this.value } return this }, }) diff --git a/package.json b/package.json index a5fcaa2..14f1475 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.24.2", + "version": "6.24.3", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": {