ig-types 6.24.13 → 6.24.15
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 +87 -75
- package/package.json +1 -1
- package/test.js +4 -3
package/Promise.js
CHANGED
|
@@ -306,18 +306,6 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
306
306
|
: list },
|
|
307
307
|
// transform/handle packed array (sync, but can return promises in the list)...
|
|
308
308
|
// XXX need a strict spec...
|
|
309
|
-
// XXX BUG???
|
|
310
|
-
// await Promise.iter([
|
|
311
|
-
// Promise.sync.resolve([1,1,1]),
|
|
312
|
-
// [2,2,2],
|
|
313
|
-
// Promise.resolve([3,3,3]),
|
|
314
|
-
// Promise.iter([4,4,4]),
|
|
315
|
-
// Promise.all([5,5,5]),
|
|
316
|
-
// ],
|
|
317
|
-
// e => e instanceof Array ? [[1,2,3]] : e)
|
|
318
|
-
// -> [ 1, 2, 3, [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ] ]
|
|
319
|
-
// ...the fist result seems odd...
|
|
320
|
-
// XXX FIXED but need to add a test for IterablePromise branch below...
|
|
321
309
|
__handle: function(list, handler=undefined, onerror=undefined){
|
|
322
310
|
var that = this
|
|
323
311
|
if(typeof(list) == 'function'){
|
|
@@ -337,40 +325,40 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
337
325
|
'smap'
|
|
338
326
|
: 'map'
|
|
339
327
|
var stop = false
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
328
|
+
// XXX do we handle generators here???
|
|
329
|
+
var each = function(elem){
|
|
330
|
+
return elem instanceof Array ?
|
|
331
|
+
elem
|
|
332
|
+
.map(handler)
|
|
333
|
+
.flat()
|
|
334
|
+
: handler(elem) }
|
|
344
335
|
return list
|
|
345
336
|
[map](
|
|
346
337
|
function(elem){
|
|
338
|
+
// NOTE: we are calling .flat() on the result so we
|
|
339
|
+
// need to keep a handled array as a single
|
|
340
|
+
// element by wrapping the return of handled(..)...
|
|
347
341
|
return elem instanceof IterablePromise ?
|
|
348
|
-
// XXX should elem be expanded??? (like Array below)
|
|
349
342
|
(elem.isSync() ?
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
: elem.iterthen(handler))
|
|
343
|
+
each(elem.sync())
|
|
344
|
+
: elem.iterthen(each))
|
|
353
345
|
// sync sync promise...
|
|
354
346
|
: (elem instanceof SyncPromise
|
|
355
347
|
&& !(elem.sync() instanceof Promise)) ?
|
|
356
|
-
[
|
|
348
|
+
[each(elem.sync())]
|
|
357
349
|
// promise / promise-like...
|
|
358
350
|
: elem && elem.then ?
|
|
359
351
|
// NOTE: when this is explicitly stopped we
|
|
360
352
|
// do not call any more handlers after
|
|
361
353
|
// STOP is thrown/returned...
|
|
362
|
-
//
|
|
354
|
+
// NOTE: the promise protects this from .flat()
|
|
363
355
|
elem.then(function(elem){
|
|
364
356
|
return !stop ?
|
|
365
|
-
|
|
357
|
+
each(elem)
|
|
366
358
|
: [] })
|
|
367
359
|
: elem instanceof Array ?
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
// a single element by wrapping the return
|
|
371
|
-
// of handled(..)...
|
|
372
|
-
[handler(unwrap(elem))]
|
|
373
|
-
: handler(elem) },
|
|
360
|
+
[each(elem)]
|
|
361
|
+
: each(elem) },
|
|
374
362
|
// handle STOP...
|
|
375
363
|
function(){
|
|
376
364
|
stop = true })
|
|
@@ -772,7 +760,8 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
772
760
|
// instance...
|
|
773
761
|
var promise
|
|
774
762
|
var obj = Reflect.construct(
|
|
775
|
-
|
|
763
|
+
Promise,
|
|
764
|
+
//this.constructor.__proto__,
|
|
776
765
|
[function(resolve, reject){
|
|
777
766
|
// NOTE: this is here for Promise compatibility...
|
|
778
767
|
if(typeof(list) == 'function'){
|
|
@@ -781,13 +770,14 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
781
770
|
if(list === false){
|
|
782
771
|
return reject() }
|
|
783
772
|
promise = {resolve, reject} }],
|
|
784
|
-
|
|
773
|
+
this.constructor)
|
|
785
774
|
|
|
786
775
|
// populate new instance...
|
|
787
776
|
if(promise){
|
|
788
777
|
// handle/pack input data...
|
|
789
778
|
if(handler != 'raw'){
|
|
790
|
-
list = list instanceof IterablePromise ?
|
|
779
|
+
//list = list instanceof IterablePromise ?
|
|
780
|
+
list = list instanceof this.constructor ?
|
|
791
781
|
obj.__handle(list.__packed, handler, onerror)
|
|
792
782
|
: obj.__pack(list, handler, onerror) }
|
|
793
783
|
Object.defineProperty(obj, '__packed', {
|
|
@@ -827,53 +817,75 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
827
817
|
//---------------------------------------------------------------------
|
|
828
818
|
// XXX EXPEREMENTAL/HACK...
|
|
829
819
|
|
|
830
|
-
//
|
|
831
|
-
//
|
|
832
|
-
//
|
|
833
|
-
//
|
|
834
|
-
//
|
|
835
|
-
//
|
|
836
|
-
//
|
|
837
|
-
//
|
|
838
|
-
//
|
|
839
|
-
//
|
|
840
|
-
//
|
|
841
|
-
//
|
|
842
|
-
//
|
|
843
|
-
//
|
|
820
|
+
// This like IterablePromise but guarantees handler execution in order
|
|
821
|
+
// element occurrence.
|
|
822
|
+
//
|
|
823
|
+
// For comparison:
|
|
824
|
+
// Promise.all([ .. ]).then(func)
|
|
825
|
+
// - func is called on element list
|
|
826
|
+
// - func is called when all the elements are resolved
|
|
827
|
+
// Promise.iter([ .. ]).iter(func)
|
|
828
|
+
// - func per element
|
|
829
|
+
// - func is called when an element is resolved/ready
|
|
830
|
+
// in any order
|
|
831
|
+
// Promise.seqiter([ .. ]).iter(func)
|
|
832
|
+
// - func per element
|
|
833
|
+
// - func is called when an element is resolved/ready
|
|
834
|
+
// and when all elements before it are handled
|
|
835
|
+
//
|
|
836
|
+
// NOTE: that here a promise will block handling of later promises even
|
|
837
|
+
// if they are resolved before it.
|
|
838
|
+
//
|
|
839
|
+
// XXX BUG:
|
|
840
|
+
// await Promise.seqiter([
|
|
841
|
+
// 1,
|
|
842
|
+
// Promise.resolve(2),
|
|
843
|
+
// Promise.resolve(3)
|
|
844
|
+
// Promise.resolve(4)
|
|
845
|
+
// Promise.resolve(5)
|
|
846
|
+
// ])
|
|
847
|
+
// -> [ 1, 2, [3], [[4]], [[[5]]] ]
|
|
848
|
+
// looks like we need to flatten things...
|
|
849
|
+
// XXX FIXED but need more testing...
|
|
844
850
|
// XXX not sure if this is a viable strategy....
|
|
845
851
|
var IterableSequentialPromise =
|
|
846
852
|
module.IterableSequentialPromise =
|
|
847
853
|
object.Constructor('IterableSequentialPromise', IterablePromise, {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
var
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
if(
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
854
|
+
// XXX needs more work...
|
|
855
|
+
__pack: function(list, handler=undefined, onerror=undefined){
|
|
856
|
+
var seqiter = this.constructor
|
|
857
|
+
|
|
858
|
+
var repack = function(list){
|
|
859
|
+
var res = []
|
|
860
|
+
for(var [i, e] of list.entries()){
|
|
861
|
+
// XXX check for .then(..) instead???
|
|
862
|
+
if(e instanceof Promise
|
|
863
|
+
// skip last promise -- nothing to wrap...
|
|
864
|
+
&& i < list.length-1){
|
|
865
|
+
res.push(e
|
|
866
|
+
.then(function(e){
|
|
867
|
+
return seqiter([...e, ...list.slice(i+1)])
|
|
868
|
+
.flat() }))
|
|
869
|
+
break }
|
|
870
|
+
res.push(e) }
|
|
871
|
+
return res }
|
|
872
|
+
|
|
873
|
+
// NOTE: we are not handling the list here...
|
|
874
|
+
list = object.parentCall(IterableSequentialPromise.prototype.__pack, this, list)
|
|
875
|
+
list = list instanceof SyncPromise ?
|
|
876
|
+
list.sync()
|
|
877
|
+
: list
|
|
878
|
+
list = list instanceof Array ?
|
|
879
|
+
repack(list)
|
|
880
|
+
// XXX check for .then(..) instead???
|
|
881
|
+
: list instanceof Promise ?
|
|
882
|
+
list.then(repack)
|
|
883
|
+
: list
|
|
884
|
+
|
|
885
|
+
return handler ?
|
|
886
|
+
// XXX this seems to be wrong...
|
|
887
|
+
this.__handle(list, handler, onerror)
|
|
888
|
+
: list },
|
|
877
889
|
})
|
|
878
890
|
|
|
879
891
|
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -267,13 +267,14 @@ var cases = test.Cases({
|
|
|
267
267
|
'promises as elements')
|
|
268
268
|
|
|
269
269
|
// XXX need a recursive assert...
|
|
270
|
-
var should_be = [ [1], [2], [3], [4], [5] ]
|
|
270
|
+
var should_be = [ [1], [2], [3], [4], [5], [6] ]
|
|
271
271
|
var got = await Promise.iter([
|
|
272
272
|
[1,1,1],
|
|
273
273
|
Promise.sync.resolve([2,2,2]),
|
|
274
274
|
Promise.resolve([3,3,3]),
|
|
275
275
|
Promise.iter([4,4,4]),
|
|
276
|
-
Promise.
|
|
276
|
+
Promise.iter.resolve([5,5,5]),
|
|
277
|
+
Promise.all([6,6,6]),
|
|
277
278
|
],
|
|
278
279
|
function(e){
|
|
279
280
|
return e instanceof Array ?
|
|
@@ -290,7 +291,7 @@ var cases = test.Cases({
|
|
|
290
291
|
&& got[i] instanceof Array
|
|
291
292
|
&& e.length == got[i].length
|
|
292
293
|
&& e[0] == got[i][0] }, true),
|
|
293
|
-
'pack/unpack')
|
|
294
|
+
'pack/unpack:', got)
|
|
294
295
|
},
|
|
295
296
|
|
|
296
297
|
// Date.js
|