ig-types 6.24.22 → 6.24.24

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.
Files changed (4) hide show
  1. package/Promise.js +26 -23
  2. package/README.md +63 -0
  3. package/package.json +1 -1
  4. package/test.js +2 -0
package/Promise.js CHANGED
@@ -944,27 +944,30 @@ object.Constructor('IterableSequentialStartPromise', IterablePromise, {
944
944
 
945
945
 
946
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
- //
947
+ // Like IterableSequentialStartPromise(..) but each handler will be
948
+ // called after the previous handler's return value is resolved (if it
949
+ // is a promise).
950
+ //
951
+ // This is needed to control the "unpredictable" behavior of await's in
952
+ // JavaScript, here is a trivial example with an async function starting
953
+ // as if it was sync and as a promise on the next execution frame:
954
+ // console.log(1)
955
+ // // note that we are NOTE await'ing for the function here...
956
+ // (async function f(){
957
+ // console.log(2)})()
958
+ // console.log(3)
959
+ // -> prints 1, 2, 3
960
+ // and:
961
+ // console.log(1)
962
+ // (async function f(){
963
+ // // note the await -- this is the only difference...
964
+ // console.log(await 2)})()
965
+ // console.log(3)
966
+ // -> prints 1, 3, 2
967
+ // this is bad because if a handler has two execution paths one with
968
+ // an await and one without the order of actual handler execution can
969
+ // not be controlled predictably unless we wait for the whole thing to
970
+ // resolve...
968
971
  var IterableSequentialPromise =
969
972
  module.IterableSequentialPromise =
970
973
  object.Constructor('IterableSequentialPromise', IterableSequentialStartPromise, {
@@ -1327,8 +1330,8 @@ object.Mixin('PromiseMixin', 'soft', {
1327
1330
  // XXX should we just check for .then(..) ???
1328
1331
  // XXX update README if this changes...
1329
1332
  : (data.length == 1
1330
- && Symbol.asyncIterator in data[0]
1331
- && 'then' in data[0]) ?
1333
+ && data[0][Symbol.asyncIterator]
1334
+ && data[0].then) ?
1332
1335
  data[0].then(func, ...error)
1333
1336
  : error.length > 0 ?
1334
1337
  function(){
package/README.md CHANGED
@@ -1651,6 +1651,69 @@ XXX should we support generators as input?
1651
1651
  XXX should we support infinite generators as input?
1652
1652
  -->
1653
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
+
1654
1717
 
1655
1718
  #### `Promise.iter(..)` / `promise.IterablePromise(..)`
1656
1719
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.24.22",
3
+ "version": "6.24.24",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -449,6 +449,8 @@ var cases = test.Cases({
449
449
  // NOTE: 4 here is present as it was handled before the promise resolved...
450
450
  [1,2,'stop'],
451
451
  '.seqiter(..): STOP(..): delayed')
452
+
453
+ // XXX test .seqstartiter(..)
452
454
  },
453
455
 
454
456
  // Date.js