ig-types 6.24.2 → 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 +23 -14
- 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'),
|
|
@@ -849,13 +853,16 @@ object.Constructor('SyncPromise', Promise, {
|
|
|
849
853
|
// mode and thus set .value and possibly .error, soe there is no
|
|
850
854
|
// need to check for .value...
|
|
851
855
|
then: function(resolve, reject){
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
856
|
+
return this.hasOwnProperty('error') ?
|
|
857
|
+
this.constructor.reject(
|
|
858
|
+
reject ?
|
|
859
|
+
reject(this.error)
|
|
860
|
+
: this.error)
|
|
861
|
+
: resolve ?
|
|
862
|
+
this.constructor.resolve(
|
|
863
|
+
resolve(this.value))
|
|
864
|
+
// XXX should we return a copy???
|
|
865
|
+
: this },
|
|
859
866
|
|
|
860
867
|
// NOTE: if func calls resolve(..) with a promise then this will return
|
|
861
868
|
// that promise...
|
|
@@ -895,10 +902,8 @@ object.Mixin('PromiseMixin', 'soft', {
|
|
|
895
902
|
iter: IterablePromise,
|
|
896
903
|
interactive: InteractivePromise,
|
|
897
904
|
cooperative: CooperativePromise,
|
|
898
|
-
// XXX EXPEREMENTAL...
|
|
899
905
|
sync: SyncPromise,
|
|
900
|
-
|
|
901
|
-
// XXX need error support...
|
|
906
|
+
// XXX should this be implemented via SyncPromise???
|
|
902
907
|
awaitOrRun: function(data, func){
|
|
903
908
|
data = [...arguments]
|
|
904
909
|
func = data.pop()
|
|
@@ -943,11 +948,15 @@ object.Mixin('PromiseProtoMixin', 'soft', {
|
|
|
943
948
|
as: ProxyPromise,
|
|
944
949
|
iter: function(handler=undefined){
|
|
945
950
|
return IterablePromise(this, handler) },
|
|
946
|
-
// XXX
|
|
947
|
-
|
|
951
|
+
// XXX should we try and return a sync value if normal promise is resolved???
|
|
952
|
+
// ...sould need to hook .then(..) to do this...
|
|
953
|
+
sync: function(error='throw'){
|
|
948
954
|
if(this instanceof SyncPromise){
|
|
949
|
-
if(
|
|
950
|
-
|
|
955
|
+
if(error !== false
|
|
956
|
+
&& 'error' in this){
|
|
957
|
+
if(typeof(error) != 'function'){
|
|
958
|
+
throw this.error }
|
|
959
|
+
return error(this.error) }
|
|
951
960
|
return this.value }
|
|
952
961
|
return this },
|
|
953
962
|
})
|
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
|
|