bugfix...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-01-04 06:39:55 +03:00
parent bbe236d284
commit fcd72b9b7b
3 changed files with 51 additions and 33 deletions

View File

@ -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

View File

@ -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": {

60
test.js
View File

@ -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