ig-types 6.24.9 → 6.24.10
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 +21 -19
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -1048,37 +1048,39 @@ object.Mixin('PromiseMixin', 'soft', {
|
|
|
1048
1048
|
cooperative: CooperativePromise,
|
|
1049
1049
|
sync: SyncPromise,
|
|
1050
1050
|
// XXX should this be implemented via SyncPromise???
|
|
1051
|
+
// XXX not sure if we need to expand async generators...
|
|
1051
1052
|
awaitOrRun: function(data, func, error){
|
|
1052
1053
|
data = [...arguments]
|
|
1053
1054
|
func = data.pop()
|
|
1054
1055
|
if(typeof(data.at(-1)) == 'function'){
|
|
1055
1056
|
error = func
|
|
1056
1057
|
func = data.pop() }
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1058
|
+
error = error ?
|
|
1059
|
+
[error]
|
|
1060
|
+
: []
|
|
1061
|
+
// check if we need to await...
|
|
1062
|
+
return data.reduce(function(res, e){
|
|
1060
1063
|
return res
|
|
1061
1064
|
|| e instanceof Promise }, false) ?
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
: error ?
|
|
1065
|
+
// NOTE: we will not reach this on empty data...
|
|
1066
|
+
(data.length > 1 ?
|
|
1067
|
+
Promise.all(data)
|
|
1068
|
+
.then(
|
|
1069
|
+
function(res){
|
|
1070
|
+
return func(...res) },
|
|
1071
|
+
...error)
|
|
1072
|
+
: data[0].then(func, ...error))
|
|
1073
|
+
// XXX not sure if we need to expand async generators...
|
|
1074
|
+
: (data.length == 1
|
|
1075
|
+
&& Symbol.asyncIterator in data[0]
|
|
1076
|
+
&& 'then' in data[0]) ?
|
|
1077
|
+
data[0].then(func, ...error)
|
|
1078
|
+
: error.length > 0 ?
|
|
1077
1079
|
function(){
|
|
1078
1080
|
try{
|
|
1079
1081
|
return func(...data)
|
|
1080
1082
|
}catch(err){
|
|
1081
|
-
return error(err) } }()
|
|
1083
|
+
return error[0](err) } }()
|
|
1082
1084
|
: func(...data) },
|
|
1083
1085
|
})
|
|
1084
1086
|
|