ig-types 6.24.3 → 6.24.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Promise.js +8 -1
- package/README.md +23 -4
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -795,6 +795,7 @@ object.Constructor('ProxyPromise', Promise, {
|
|
|
795
795
|
|
|
796
796
|
//---------------------------------------------------------------------
|
|
797
797
|
|
|
798
|
+
// XXX should this support async generators???
|
|
798
799
|
var syncAllProxy =
|
|
799
800
|
function(name){
|
|
800
801
|
return function(lst){
|
|
@@ -809,6 +810,7 @@ function(name){
|
|
|
809
810
|
: Promise[name](lst) } }
|
|
810
811
|
|
|
811
812
|
// XXX REVISE/TEST...
|
|
813
|
+
// XXX should this support async generators???
|
|
812
814
|
var syncAnyProxy =
|
|
813
815
|
function(name){
|
|
814
816
|
return function(lst){
|
|
@@ -837,6 +839,8 @@ object.Constructor('SyncPromise', Promise, {
|
|
|
837
839
|
return new this(function(resolve){ resolve(value) }) },
|
|
838
840
|
reject: function(error){
|
|
839
841
|
return new this(function(_, reject){ reject(error) }) },
|
|
842
|
+
// NOTE: these essentially add a special case where the inputs are
|
|
843
|
+
// either not promises or SyncPromise instances...
|
|
840
844
|
all: syncAllProxy('all'),
|
|
841
845
|
allSettled: syncAllProxy('allSettled'),
|
|
842
846
|
any: syncAnyProxy('any'),
|
|
@@ -944,9 +948,12 @@ object.Mixin('PromiseProtoMixin', 'soft', {
|
|
|
944
948
|
as: ProxyPromise,
|
|
945
949
|
iter: function(handler=undefined){
|
|
946
950
|
return IterablePromise(this, handler) },
|
|
951
|
+
// XXX should we try and return a sync value if normal promise is resolved???
|
|
952
|
+
// ...sould need to hook .then(..) to do this...
|
|
947
953
|
sync: function(error='throw'){
|
|
948
954
|
if(this instanceof SyncPromise){
|
|
949
|
-
if(
|
|
955
|
+
if(error !== false
|
|
956
|
+
&& 'error' in this){
|
|
950
957
|
if(typeof(error) != 'function'){
|
|
951
958
|
throw this.error }
|
|
952
959
|
return error(this.error) }
|
package/README.md
CHANGED
|
@@ -2034,10 +2034,29 @@ Example:
|
|
|
2034
2034
|
-->
|
|
2035
2035
|
|
|
2036
2036
|
|
|
2037
|
-
#### `<promise>.sync()`
|
|
2037
|
+
#### `<promise>.sync(..)`
|
|
2038
2038
|
|
|
2039
2039
|
Synchronously return the resolved value if `<sync-promise>` resolved, and
|
|
2040
|
-
if it _rejected_ then re-throw the `<error>`.
|
|
2040
|
+
if it _rejected_ then re-throw the `<error>`. Normal promises will return self.
|
|
2041
|
+
|
|
2042
|
+
```bnf
|
|
2043
|
+
<promise>.sync()
|
|
2044
|
+
-> <value>
|
|
2045
|
+
-> <promise>
|
|
2046
|
+
```
|
|
2047
|
+
|
|
2048
|
+
To suppress errors pass `false` to `.sync(..)` and to handle them differently
|
|
2049
|
+
pass an error handler function.
|
|
2050
|
+
```bnf
|
|
2051
|
+
<promise>.sync(false)
|
|
2052
|
+
-> <value>
|
|
2053
|
+
|
|
2054
|
+
<promise>.sync(<onerror>)
|
|
2055
|
+
-> <value>
|
|
2056
|
+
|
|
2057
|
+
<onerror>(<error>)
|
|
2058
|
+
-> <value>
|
|
2059
|
+
```
|
|
2041
2060
|
|
|
2042
2061
|
|
|
2043
2062
|
#### `<sync-promise>.value` / `<sync-promise>.error`
|
|
@@ -2048,8 +2067,8 @@ rejection `.error`.
|
|
|
2048
2067
|
|
|
2049
2068
|
#### `Promise.sync.all(..)` / `Promise.sync.allSettled(..)` / `Promise.sync.any(..)` / `Promise.sync.race(..)`
|
|
2050
2069
|
|
|
2051
|
-
Equivalents to `Promise`'s
|
|
2052
|
-
items in the input are either non-promises or `<sync-promise>`s.
|
|
2070
|
+
Equivalents to `Promise`'s respective versions but will run sync if the
|
|
2071
|
+
relevant items in the input are either non-promises or `<sync-promise>`s.
|
|
2053
2072
|
|
|
2054
2073
|
|
|
2055
2074
|
|