diff --git a/Promise.js b/Promise.js index 9577bc0..44ea89a 100644 --- a/Promise.js +++ b/Promise.js @@ -948,9 +948,12 @@ object.Mixin('PromiseProtoMixin', 'soft', { as: ProxyPromise, iter: function(handler=undefined){ return IterablePromise(this, handler) }, + // XXX should we try and return a sync value if normal promise is resolved??? + // ...sould need to hook .then(..) to do this... sync: function(error='throw'){ if(this instanceof SyncPromise){ - if('error' in this){ + if(error !== false + && 'error' in this){ if(typeof(error) != 'function'){ throw this.error } return error(this.error) } diff --git a/README.md b/README.md index 80d99a0..9c6c5dd 100644 --- a/README.md +++ b/README.md @@ -2034,10 +2034,29 @@ Example: --> -#### `.sync()` +#### `.sync(..)` Synchronously return the resolved value if `` resolved, and -if it _rejected_ then re-throw the ``. +if it _rejected_ then re-throw the ``. Normal promises will return self. + +```bnf +.sync() + -> + -> +``` + +To suppress errors pass `false` to `.sync(..)` and to handle them differently +pass an error handler function. +```bnf +.sync(false) + -> + +.sync() + -> + +() + -> +``` #### `.value` / `.error` @@ -2048,8 +2067,8 @@ rejection `.error`. #### `Promise.sync.all(..)` / `Promise.sync.allSettled(..)` / `Promise.sync.any(..)` / `Promise.sync.race(..)` -Equivalents to `Promise`'s version but will run sync if the relevant -items in the input are either non-promises or ``s. +Equivalents to `Promise`'s respective versions but will run sync if the +relevant items in the input are either non-promises or ``s. diff --git a/package.json b/package.json index 14f1475..fac4328 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.24.3", + "version": "6.24.4", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": {