From fcd72b9b7b1f40bc78d5df5fafc741cee7f3b10c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 4 Jan 2023 06:39:55 +0300 Subject: [PATCH] bugfix... Signed-off-by: Alex A. Naanou --- Promise.js | 22 +++++++++++++------ package.json | 2 +- test.js | 60 +++++++++++++++++++++++++++++----------------------- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Promise.js b/Promise.js index ee15a16..9d5842a 100644 --- a/Promise.js +++ b/Promise.js @@ -840,13 +840,21 @@ object.Constructor('IterablePromise', Promise, { // await Promise.seqiter([ // 1, // Promise.resolve(2), -// Promise.resolve(3) -// Promise.resolve(4) -// Promise.resolve(5) +// Promise.resolve(3), +// Promise.resolve(4), +// Promise.resolve(5), // ]) // -> [ 1, 2, [3], [[4]], [[[5]]] ] // looks like we need to flatten things... // XXX FIXED but need more testing... +// XXX BUG (FIXED): +// await Promise.seqiter([ +// [1], +// Promise.resolve([1]), +// Promise.resolve([1]) +// ], +// e => [e]) +// -> [ [ 1 ], 1, [ 1 ] ] // XXX check if this behaves correctly (call order) on concatenation and // other methods... // XXX not sure if this is a viable strategy.... @@ -860,13 +868,14 @@ object.Constructor('IterableSequentialPromise', IterablePromise, { var res = [] for(var [i, e] of list.entries()){ // XXX check for .then(..) instead??? - if(e instanceof Promise + //if(e instanceof Promise + if(e.then // skip last promise -- nothing to wrap... && i < list.length-1){ res.push(e .then(function(e){ return seqiter( - [...e, ...list.slice(i+1)]) + [e, ...list.slice(i+1)]) .flat() })) break } res.push(e) } @@ -880,7 +889,8 @@ object.Constructor('IterableSequentialPromise', IterablePromise, { list = list instanceof Array ? repack(list) // XXX check for .then(..) instead??? - : list instanceof Promise ? + //: list instanceof Promise ? + : list.then ? list.then(repack) : list diff --git a/package.json b/package.json index f36d8b6..4f8b7b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.24.15", + "version": "6.24.16", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": { diff --git a/test.js b/test.js index 5cd5113..5a3aeae 100755 --- a/test.js +++ b/test.js @@ -266,32 +266,40 @@ var cases = test.Cases({ [1, 2, 3], 'promises as elements') - // XXX need a recursive assert... - var should_be = [ [1], [2], [3], [4], [5], [6] ] - var got = await Promise.iter([ - [1,1,1], - Promise.sync.resolve([2,2,2]), - Promise.resolve([3,3,3]), - Promise.iter([4,4,4]), - Promise.iter.resolve([5,5,5]), - Promise.all([6,6,6]), - ], - function(e){ - return e instanceof Array ? - [[ e[0] ]] - // XXX - : e }) - assert( - should_be - .reduce(function(res, e, i){ - //console.log('---', e, got[i]) - if(res === false){ - return false } - return e instanceof Array - && got[i] instanceof Array - && e.length == got[i].length - && e[0] == got[i][0] }, true), - 'pack/unpack:', got) + // XXX split this into separate cases... + for(var meth of ['iter', 'seqiter']){ + // XXX need a recursive assert... + var should_be = [ [1], [2], [3], [4], [5], [6] ] + var got = await Promise[meth]([ + [1,1,1], + Promise.sync.resolve([2,2,2]), + Promise.resolve([3,3,3]), + Promise.iter([4,4,4]), + Promise.iter.resolve([5,5,5]), + Promise.all([6,6,6]), + ], + function(e){ + return e instanceof Array ? + [[ e[0] ]] + // XXX + : e }) + assert( + should_be + .reduce(function(res, e, i){ + //console.log('---', e, got[i]) + if(res === false){ + return false } + return e instanceof Array + && got[i] instanceof Array + && e.length == got[i].length + && e[0] == got[i][0] }, true), + 'pack/unpack', meth, got) + + assert.array( + await Promise[meth]([1, Promise.resolve(2), Promise.resolve(3)]), + [1,2,3], + 'flat unpack', meth) + } }, // Date.js