ig-types 6.24.15 → 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.
Files changed (3) hide show
  1. package/Promise.js +8 -16
  2. package/package.json +1 -1
  3. package/test.js +34 -26
package/Promise.js CHANGED
@@ -836,22 +836,12 @@ object.Constructor('IterablePromise', Promise, {
836
836
  // NOTE: that here a promise will block handling of later promises even
837
837
  // if they are resolved before it.
838
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...
839
+ // XXX check if this behaves correctly (call order) on concatenation and
840
+ // other methods...
850
841
  // XXX not sure if this is a viable strategy....
851
842
  var IterableSequentialPromise =
852
843
  module.IterableSequentialPromise =
853
844
  object.Constructor('IterableSequentialPromise', IterablePromise, {
854
- // XXX needs more work...
855
845
  __pack: function(list, handler=undefined, onerror=undefined){
856
846
  var seqiter = this.constructor
857
847
 
@@ -859,12 +849,14 @@ object.Constructor('IterableSequentialPromise', IterablePromise, {
859
849
  var res = []
860
850
  for(var [i, e] of list.entries()){
861
851
  // XXX check for .then(..) instead???
862
- if(e instanceof Promise
852
+ //if(e instanceof Promise
853
+ if(e.then
863
854
  // skip last promise -- nothing to wrap...
864
855
  && i < list.length-1){
865
856
  res.push(e
866
857
  .then(function(e){
867
- return seqiter([...e, ...list.slice(i+1)])
858
+ return seqiter(
859
+ [e, ...list.slice(i+1)])
868
860
  .flat() }))
869
861
  break }
870
862
  res.push(e) }
@@ -878,12 +870,12 @@ object.Constructor('IterableSequentialPromise', IterablePromise, {
878
870
  list = list instanceof Array ?
879
871
  repack(list)
880
872
  // XXX check for .then(..) instead???
881
- : list instanceof Promise ?
873
+ //: list instanceof Promise ?
874
+ : list.then ?
882
875
  list.then(repack)
883
876
  : list
884
877
 
885
878
  return handler ?
886
- // XXX this seems to be wrong...
887
879
  this.__handle(list, handler, onerror)
888
880
  : list },
889
881
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.24.15",
3
+ "version": "6.24.16",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {
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 need a recursive assert...
270
- var should_be = [ [1], [2], [3], [4], [5], [6] ]
271
- var got = await Promise.iter([
272
- [1,1,1],
273
- Promise.sync.resolve([2,2,2]),
274
- Promise.resolve([3,3,3]),
275
- Promise.iter([4,4,4]),
276
- Promise.iter.resolve([5,5,5]),
277
- Promise.all([6,6,6]),
278
- ],
279
- function(e){
280
- return e instanceof Array ?
281
- [[ e[0] ]]
282
- // XXX
283
- : e })
284
- assert(
285
- should_be
286
- .reduce(function(res, e, i){
287
- //console.log('---', e, got[i])
288
- if(res === false){
289
- return false }
290
- return e instanceof Array
291
- && got[i] instanceof Array
292
- && e.length == got[i].length
293
- && e[0] == got[i][0] }, true),
294
- 'pack/unpack:', got)
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