mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
more tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ea242452bb
commit
62c00a9fd4
@ -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) }
|
||||
|
||||
27
README.md
27
README.md
@ -2034,10 +2034,29 @@ Example:
|
||||
-->
|
||||
|
||||
|
||||
#### `<promise>.sync()`
|
||||
#### `<promise>.sync(..)`
|
||||
|
||||
Synchronously return the resolved value if `<sync-promise>` resolved, and
|
||||
if it _rejected_ then re-throw the `<error>`.
|
||||
if it _rejected_ then re-throw the `<error>`. Normal promises will return self.
|
||||
|
||||
```bnf
|
||||
<promise>.sync()
|
||||
-> <value>
|
||||
-> <promise>
|
||||
```
|
||||
|
||||
To suppress errors pass `false` to `.sync(..)` and to handle them differently
|
||||
pass an error handler function.
|
||||
```bnf
|
||||
<promise>.sync(false)
|
||||
-> <value>
|
||||
|
||||
<promise>.sync(<onerror>)
|
||||
-> <value>
|
||||
|
||||
<onerror>(<error>)
|
||||
-> <value>
|
||||
```
|
||||
|
||||
|
||||
#### `<sync-promise>.value` / `<sync-promise>.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 `<sync-promise>`s.
|
||||
Equivalents to `Promise`'s respective versions but will run sync if the
|
||||
relevant items in the input are either non-promises or `<sync-promise>`s.
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user