ig-types 6.24.14 → 6.24.16
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 +31 -6
- package/package.json +1 -1
- package/test.js +34 -26
package/Promise.js
CHANGED
|
@@ -817,11 +817,31 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
817
817
|
//---------------------------------------------------------------------
|
|
818
818
|
// XXX EXPEREMENTAL/HACK...
|
|
819
819
|
|
|
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 check if this behaves correctly (call order) on concatenation and
|
|
840
|
+
// other methods...
|
|
820
841
|
// XXX not sure if this is a viable strategy....
|
|
821
842
|
var IterableSequentialPromise =
|
|
822
843
|
module.IterableSequentialPromise =
|
|
823
844
|
object.Constructor('IterableSequentialPromise', IterablePromise, {
|
|
824
|
-
// XXX needs more work...
|
|
825
845
|
__pack: function(list, handler=undefined, onerror=undefined){
|
|
826
846
|
var seqiter = this.constructor
|
|
827
847
|
|
|
@@ -829,28 +849,33 @@ object.Constructor('IterableSequentialPromise', IterablePromise, {
|
|
|
829
849
|
var res = []
|
|
830
850
|
for(var [i, e] of list.entries()){
|
|
831
851
|
// XXX check for .then(..) instead???
|
|
832
|
-
if(e instanceof Promise
|
|
852
|
+
//if(e instanceof Promise
|
|
853
|
+
if(e.then
|
|
833
854
|
// skip last promise -- nothing to wrap...
|
|
834
855
|
&& i < list.length-1){
|
|
835
856
|
res.push(e
|
|
836
857
|
.then(function(e){
|
|
837
|
-
return seqiter(
|
|
858
|
+
return seqiter(
|
|
859
|
+
[e, ...list.slice(i+1)])
|
|
860
|
+
.flat() }))
|
|
838
861
|
break }
|
|
839
862
|
res.push(e) }
|
|
840
863
|
return res }
|
|
841
864
|
|
|
842
865
|
// NOTE: we are not handling the list here...
|
|
843
866
|
list = object.parentCall(IterableSequentialPromise.prototype.__pack, this, list)
|
|
844
|
-
|
|
867
|
+
list = list instanceof SyncPromise ?
|
|
868
|
+
list.sync()
|
|
869
|
+
: list
|
|
845
870
|
list = list instanceof Array ?
|
|
846
871
|
repack(list)
|
|
847
872
|
// XXX check for .then(..) instead???
|
|
848
|
-
|
|
873
|
+
//: list instanceof Promise ?
|
|
874
|
+
: list.then ?
|
|
849
875
|
list.then(repack)
|
|
850
876
|
: list
|
|
851
877
|
|
|
852
878
|
return handler ?
|
|
853
|
-
// XXX this seems to be wrong...
|
|
854
879
|
this.__handle(list, handler, onerror)
|
|
855
880
|
: list },
|
|
856
881
|
})
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -266,32 +266,40 @@ var cases = test.Cases({
|
|
|
266
266
|
[1, 2, 3],
|
|
267
267
|
'promises as elements')
|
|
268
268
|
|
|
269
|
-
// XXX
|
|
270
|
-
var
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
269
|
+
// XXX split this into separate cases...
|
|
270
|
+
for(var meth of ['iter', 'seqiter']){
|
|
271
|
+
// XXX need a recursive assert...
|
|
272
|
+
var should_be = [ [1], [2], [3], [4], [5], [6] ]
|
|
273
|
+
var got = await Promise[meth]([
|
|
274
|
+
[1,1,1],
|
|
275
|
+
Promise.sync.resolve([2,2,2]),
|
|
276
|
+
Promise.resolve([3,3,3]),
|
|
277
|
+
Promise.iter([4,4,4]),
|
|
278
|
+
Promise.iter.resolve([5,5,5]),
|
|
279
|
+
Promise.all([6,6,6]),
|
|
280
|
+
],
|
|
281
|
+
function(e){
|
|
282
|
+
return e instanceof Array ?
|
|
283
|
+
[[ e[0] ]]
|
|
284
|
+
// XXX
|
|
285
|
+
: e })
|
|
286
|
+
assert(
|
|
287
|
+
should_be
|
|
288
|
+
.reduce(function(res, e, i){
|
|
289
|
+
//console.log('---', e, got[i])
|
|
290
|
+
if(res === false){
|
|
291
|
+
return false }
|
|
292
|
+
return e instanceof Array
|
|
293
|
+
&& got[i] instanceof Array
|
|
294
|
+
&& e.length == got[i].length
|
|
295
|
+
&& e[0] == got[i][0] }, true),
|
|
296
|
+
'pack/unpack', meth, got)
|
|
297
|
+
|
|
298
|
+
assert.array(
|
|
299
|
+
await Promise[meth]([1, Promise.resolve(2), Promise.resolve(3)]),
|
|
300
|
+
[1,2,3],
|
|
301
|
+
'flat unpack', meth)
|
|
302
|
+
}
|
|
295
303
|
},
|
|
296
304
|
|
|
297
305
|
// Date.js
|