found bug, not isolated yet...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-06-15 16:44:16 +03:00
parent 0595479171
commit db83dd7575
2 changed files with 57 additions and 0 deletions

View File

@ -523,6 +523,20 @@ object.Constructor('IterablePromise', Promise, {
// NOTE: if 'types/Array' is imported this will support throwing STOP,
// for more info see notes for .__pack(..)
// XXX EXPEREMENTAL: STOP...
//
// XXX BUG:
// await Promise.iter(['a', Promise.resolve(222), ['c']])
// .map(async e => e)
// -> ['a', <promise>, ['c']]
// is not the same as:
// await Promise.iter(['a', Promise.resolve(222), ['c']])
// .map(e => e)
// -> ['a', 222, ['c']]
// ...and these works as expected:
// await Promise.iter(['a', Promise.resolve(222), ['c']], async e => [e])
// -> ['a', 222, ['c']]
// await Promise.iter(['a', Promise.resolve(222), ['c']], e => [e])
// -> ['a', 222, ['c']]
__new__: function(_, list, handler){
// instance...
var promise

View File

@ -66,6 +66,14 @@ module.Generator =
(function*(){}).constructor
var AsyncGeneratorPrototype =
(async function*(){}).constructor.prototype
var AsyncGenerator =
module.AsyncGenerator =
(async function*(){}).constructor
// base iterator prototypes...
var ITERATOR_PROTOTYPES = [
Array,
@ -428,6 +436,41 @@ ITERATOR_PROTOTYPES
GeneratorProtoMixin(proto) })
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX EXPERIMENTAL...
var makeAsyncGenerator = function(name, pre){
return function(...args){
var that = this
return Object.assign(
async function*(){
var a = pre ?
pre.call(this, args, ...arguments)
: args
for await (var e of that(...arguments)[name](...a)){
yield e } },
{ toString: function(){
return [
that.toString(),
// XXX need to normalize args better...
`.${ name }(${ args.join(', ') })`,
].join('\n ') }, }) } }
var AsyncGeneratorMixin =
module.AsyncGeneratorMixin =
object.Mixin('AsyncGeneratorMixin', 'soft', {
map: makeAsyncGenerator('map'),
})
var AsyncGeneratorProtoMixin =
module.AsyncGeneratorProtoMixin =
object.Mixin('AsyncGeneratorProtoMixin', 'soft', {
})
//AsyncGeneratorMixin(AsyncGeneratorPrototype)
//AsyncGeneratorProtoMixin(AsyncGeneratorPrototype.prototype)
//---------------------------------------------------------------------
// Generators...