ig-types 6.24.21 → 6.24.23
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 +77 -0
- package/package.json +1 -1
- package/test.js +2 -0
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)
|
|
@@ -1647,6 +1651,69 @@ XXX should we support generators as input?
|
|
|
1647
1651
|
XXX should we support infinite generators as input?
|
|
1648
1652
|
-->
|
|
1649
1653
|
|
|
1654
|
+
Promise iteration supports three modes of synchronization:
|
|
1655
|
+
|
|
1656
|
+
1. handle on ready
|
|
1657
|
+
```
|
|
1658
|
+
.iter(
|
|
1659
|
+
[value, promise, promise, value], handler)
|
|
1660
|
+
+ . . +
|
|
1661
|
+
| R |
|
|
1662
|
+
+ R | +
|
|
1663
|
+
| +
|
|
1664
|
+
+ - - - - - - - - - - - - - - - -> resolve
|
|
1665
|
+
|
|
1666
|
+
R - input resolved
|
|
1667
|
+
```
|
|
1668
|
+
A handler is started as soon as it's value is ready/resolved, i.e.
|
|
1669
|
+
for non-promise values start immediately.
|
|
1670
|
+
|
|
1671
|
+
|
|
1672
|
+
2. handle sequentially when value is ready and previous handler is started
|
|
1673
|
+
```
|
|
1674
|
+
.seqstartiter(
|
|
1675
|
+
[value, promise, promise, value], handler)
|
|
1676
|
+
+ . . . |
|
|
1677
|
+
| R <-+
|
|
1678
|
+
++- - >R . . |
|
|
1679
|
+
| | <-+
|
|
1680
|
+
+ ++ - - - >+ . |
|
|
1681
|
+
. | | <-+
|
|
1682
|
+
+ + - - > + |
|
|
1683
|
+
. . | <-+
|
|
1684
|
+
+ - - - - - - - > resolve
|
|
1685
|
+
^ ^
|
|
1686
|
+
+------+-- returned promise
|
|
1687
|
+
R - input resolved
|
|
1688
|
+
```
|
|
1689
|
+
A handler is started as soon as all previous handlers are started
|
|
1690
|
+
and the current value is ready/resolved.
|
|
1691
|
+
|
|
1692
|
+
|
|
1693
|
+
3. handle sequentially when value is ready and previous handler is resolved
|
|
1694
|
+
```
|
|
1695
|
+
.seqiter(
|
|
1696
|
+
[value, promise, promise, value], handler)
|
|
1697
|
+
+ . . . |
|
|
1698
|
+
| R <-+
|
|
1699
|
+
++- - >R . . |
|
|
1700
|
+
| | <-+
|
|
1701
|
+
+ ++ . . |
|
|
1702
|
+
. | |
|
|
1703
|
+
+ - - - >+ . |
|
|
1704
|
+
. . | <-+
|
|
1705
|
+
+ - - > + |
|
|
1706
|
+
. . | <-+
|
|
1707
|
+
+ - - - - - - - > resolve
|
|
1708
|
+
^ ^
|
|
1709
|
+
+------+-- returned promise
|
|
1710
|
+
R - input resolved
|
|
1711
|
+
```
|
|
1712
|
+
A handler is started as soon as all previous handlers are done, their
|
|
1713
|
+
return values are resolved and the current value is ready/resolved.
|
|
1714
|
+
|
|
1715
|
+
|
|
1716
|
+
|
|
1650
1717
|
|
|
1651
1718
|
#### `Promise.iter(..)` / `promise.IterablePromise(..)`
|
|
1652
1719
|
|
|
@@ -1681,6 +1748,16 @@ Return a shallow copy of the current promise iterator.
|
|
|
1681
1748
|
```
|
|
1682
1749
|
|
|
1683
1750
|
|
|
1751
|
+
#### `Promise.seqiter(..)` / `promise.IterableSequentialPromise(..)`
|
|
1752
|
+
|
|
1753
|
+
#### `<promise>.seqiter()` / `<promise-iter>.seqiter()`
|
|
1754
|
+
|
|
1755
|
+
#### `Promise.seqstartiter(..)` / `promise.IterableSequentialStartPromise(..)`
|
|
1756
|
+
|
|
1757
|
+
#### `<promise>.seqstartiter()` / `<promise-iter>.seqstartiter()`
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1684
1761
|
#### `<promise-iter>.map(..)` / `<promise-iter>.filter(..)` / `<promise-iter>.reduce(..)`
|
|
1685
1762
|
|
|
1686
1763
|
Methods similar but not fully equivalent to `Array`'s
|
package/package.json
CHANGED