ig-types 6.24.21 → 6.24.22
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 +51 -7
- package/README.md +14 -0
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -880,7 +880,10 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
880
880
|
// Promise.iter([ .. ]).iter(func)
|
|
881
881
|
// - func per element
|
|
882
882
|
// - func is called when an element is resolved/ready
|
|
883
|
-
// in order of resolution
|
|
883
|
+
// in order of resolution
|
|
884
|
+
// Promise.seqstartiter([ .. ]).iter(func)
|
|
885
|
+
// - func per element
|
|
886
|
+
// - func is called when an element is resolved/ready
|
|
884
887
|
// Promise.seqiter([ .. ]).iter(func)
|
|
885
888
|
// - func per element
|
|
886
889
|
// - func is called when an element is resolved/ready
|
|
@@ -899,9 +902,9 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
899
902
|
// XXX check if this behaves correctly (call order) on concatenation and
|
|
900
903
|
// other methods...
|
|
901
904
|
// XXX not sure if this is a viable strategy....
|
|
902
|
-
var
|
|
903
|
-
module.
|
|
904
|
-
object.Constructor('
|
|
905
|
+
var IterableSequentialStartPromise =
|
|
906
|
+
module.IterableSequentialStartPromise =
|
|
907
|
+
object.Constructor('IterableSequentialStartPromise', IterablePromise, {
|
|
905
908
|
__pack: function(list, handler=undefined, onerror=undefined){
|
|
906
909
|
var seqiter = this.constructor
|
|
907
910
|
|
|
@@ -924,7 +927,7 @@ object.Constructor('IterableSequentialPromise', IterablePromise, {
|
|
|
924
927
|
return res }
|
|
925
928
|
|
|
926
929
|
// NOTE: we are not handling the list here...
|
|
927
|
-
list = object.parentCall(
|
|
930
|
+
list = object.parentCall(IterableSequentialStartPromise.prototype.__pack, this, list)
|
|
928
931
|
list = list instanceof SyncPromise ?
|
|
929
932
|
list.sync()
|
|
930
933
|
: list
|
|
@@ -940,6 +943,46 @@ object.Constructor('IterableSequentialPromise', IterablePromise, {
|
|
|
940
943
|
})
|
|
941
944
|
|
|
942
945
|
|
|
946
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
947
|
+
// XXX might also be a good idea to implement a version of the above to
|
|
948
|
+
// handle the next element only after the promise returned by the
|
|
949
|
+
// previous handler is resolved -- depth first...
|
|
950
|
+
// ...this would help prevent the await execution uncertainty, i.e.:
|
|
951
|
+
// console.log(1)
|
|
952
|
+
// // note that we are NOTE await'ing for the function here...
|
|
953
|
+
// (async function f(){
|
|
954
|
+
// console.log(2)})()
|
|
955
|
+
// console.log(3)
|
|
956
|
+
// -> prints 1, 2, 3
|
|
957
|
+
// and:
|
|
958
|
+
// console.log(1)
|
|
959
|
+
// (async function f(){
|
|
960
|
+
// // note the await -- this is the only difference...
|
|
961
|
+
// console.log(await 2)})()
|
|
962
|
+
// console.log(3)
|
|
963
|
+
// -> prints 1, 3, 2
|
|
964
|
+
// this is bad because of a handler has two execution paths one with
|
|
965
|
+
// an await and one without the order of actual handler execution can
|
|
966
|
+
// not be controlled unless we wait for the whole thing to resolve...
|
|
967
|
+
//
|
|
968
|
+
var IterableSequentialPromise =
|
|
969
|
+
module.IterableSequentialPromise =
|
|
970
|
+
object.Constructor('IterableSequentialPromise', IterableSequentialStartPromise, {
|
|
971
|
+
__handle: function(list, handler, onerror){
|
|
972
|
+
var prev = undefined
|
|
973
|
+
return object.parentCall(IterableSequentialPromise.prototype.__handle, this,
|
|
974
|
+
list,
|
|
975
|
+
// call the next handler only when the promise returned by
|
|
976
|
+
// the previous handler is resolved...
|
|
977
|
+
function(elem){
|
|
978
|
+
if(prev instanceof Promise){
|
|
979
|
+
return (prev = prev
|
|
980
|
+
.then(function(){
|
|
981
|
+
return handler(elem) })) }
|
|
982
|
+
return (prev = handler(elem)) },
|
|
983
|
+
...[...arguments].slice(2)) },
|
|
984
|
+
})
|
|
985
|
+
|
|
943
986
|
|
|
944
987
|
//---------------------------------------------------------------------
|
|
945
988
|
// Interactive promise...
|
|
@@ -1247,7 +1290,7 @@ var PromiseMixin =
|
|
|
1247
1290
|
module.PromiseMixin =
|
|
1248
1291
|
object.Mixin('PromiseMixin', 'soft', {
|
|
1249
1292
|
iter: IterablePromise,
|
|
1250
|
-
|
|
1293
|
+
seqstartiter: IterableSequentialStartPromise,
|
|
1251
1294
|
seqiter: IterableSequentialPromise,
|
|
1252
1295
|
|
|
1253
1296
|
interactive: InteractivePromise,
|
|
@@ -1306,7 +1349,8 @@ object.Mixin('PromiseProtoMixin', 'soft', {
|
|
|
1306
1349
|
|
|
1307
1350
|
iter: function(handler=undefined, onerror=undefined){
|
|
1308
1351
|
return IterablePromise(this, handler, onerror) },
|
|
1309
|
-
|
|
1352
|
+
seqstartiter: function(handler=undefined, onerror=undefined){
|
|
1353
|
+
return IterableSequentialStartPromise(this, handler, onerror) },
|
|
1310
1354
|
seqiter: function(handler=undefined, onerror=undefined){
|
|
1311
1355
|
return IterableSequentialPromise(this, handler, onerror) },
|
|
1312
1356
|
|
package/README.md
CHANGED
|
@@ -76,6 +76,10 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
76
76
|
- [`Promise.iter(..)` / `promise.IterablePromise(..)`](#promiseiter--promiseiterablepromise)
|
|
77
77
|
- [`<promise>.iter()`](#promiseiter)
|
|
78
78
|
- [`<promise-iter>.iter()`](#promise-iteriter)
|
|
79
|
+
- [`Promise.seqiter(..)` / `promise.IterableSequentialPromise(..)`](#promiseseqiter--iterablesequentialpromise)
|
|
80
|
+
- [`<promise>.seqiter()` / `<promise-iter>.seqiter()`](#promiseseqiter--promise-iterseqiter)
|
|
81
|
+
- [`Promise.seqstartiter(..)` / `promise.IterableSequentialStartPromise(..)`](#promiseseqiter--iterablesequentialstartpromise)
|
|
82
|
+
- [`<promise>.seqstartiter()` / `<promise-iter>.seqstartiter()`](#promiseseqstartiter--promise-iterseqstartiter)
|
|
79
83
|
- [`<promise-iter>.map(..)` / `<promise-iter>.filter(..)` / `<promise-iter>.reduce(..)`](#promise-itermap--promise-iterfilter--promise-iterreduce)
|
|
80
84
|
- [`<promise-iter>.between(..)`](#promise-iterbetween)
|
|
81
85
|
- [`<promise-iter>.flat(..)`](#promise-iterflat)
|
|
@@ -1681,6 +1685,16 @@ Return a shallow copy of the current promise iterator.
|
|
|
1681
1685
|
```
|
|
1682
1686
|
|
|
1683
1687
|
|
|
1688
|
+
#### `Promise.seqiter(..)` / `promise.IterableSequentialPromise(..)`
|
|
1689
|
+
|
|
1690
|
+
#### `<promise>.seqiter()` / `<promise-iter>.seqiter()`
|
|
1691
|
+
|
|
1692
|
+
#### `Promise.seqstartiter(..)` / `promise.IterableSequentialStartPromise(..)`
|
|
1693
|
+
|
|
1694
|
+
#### `<promise>.seqstartiter()` / `<promise-iter>.seqstartiter()`
|
|
1695
|
+
|
|
1696
|
+
|
|
1697
|
+
|
|
1684
1698
|
#### `<promise-iter>.map(..)` / `<promise-iter>.filter(..)` / `<promise-iter>.reduce(..)`
|
|
1685
1699
|
|
|
1686
1700
|
Methods similar but not fully equivalent to `Array`'s
|