thinking about adding STOP (partial) support to promise iteration...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-05-27 08:46:51 +03:00
parent 90fe7eb818
commit 00ea1825cd
2 changed files with 30 additions and 1 deletions

View File

@ -31,7 +31,7 @@ module.STOP =
// Wrap .map(..) / .filter(..) / .reduce(..) / .. to support STOP...
//
// NOTE: internally these are implemented as for-of loops...
// NOTE: internally these are implemented as for-of loops (./generator.js)
var stoppableList = function(iter){
return function(func){
return [...this.iter()[iter](...arguments)] } }

View File

@ -28,9 +28,21 @@
var object = require('ig-object')
// XXX required for STOP...
//var generator = require('./generator')
/*********************************************************************/
/* XXX not used yet...
// NOTE: this is used in a similar fashion to Python's StopIteration...
var STOP =
module.STOP =
object.STOP
//*/
//---------------------------------------------------------------------
// Iterable promise...
//
// Like Promise.all(..) but adds ability to iterate through results
@ -40,6 +52,9 @@ var object = require('ig-object')
var IterablePromise =
module.IterablePromise =
object.Constructor('IterablePromise', Promise, {
// XXX
//STOP: object.STOP,
//
// Format:
// [
@ -202,6 +217,7 @@ object.Constructor('IterablePromise', Promise, {
IterablePromise)
if(promise){
//var __stop = false
// apply handler(..) to the list...
//
// NOTE: the top level promises are not wrapped in arrays...
@ -209,10 +225,21 @@ object.Constructor('IterablePromise', Promise, {
// apply the handler...
handler ?
// XXX can we handle STOP here???
// ...we will not be able to stop already started
// promises...
list.map(function(block){
//* XXX STOP...
return (block instanceof Array ?
block
: [block])
/*/
// NOTE: we are not using Array's .iter() so as to
// keep the dependency minimal...
return generator.iter(
block instanceof Array ?
block
: [block])
//*/
.map(function(e){
// NOTE: we are counting actual expanded
// values and not the "blocks"...
@ -223,6 +250,8 @@ object.Constructor('IterablePromise', Promise, {
// basic value...
: handler(e) }) })
.flat()
// XXX STOP
//.toArray()
// normal constructor...
: handler === undefined ?
list.map(function(e){