From 90fe7eb818a16e78c403d508279cf83536641afc Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 26 May 2021 11:57:21 +0300 Subject: [PATCH] notes... Signed-off-by: Alex A. Naanou --- Promise.js | 42 +++++++++++++++++++++++++++--------------- README.md | 10 +++++----- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Promise.js b/Promise.js index 52452e2..275ad3a 100644 --- a/Promise.js +++ b/Promise.js @@ -80,25 +80,28 @@ object.Constructor('IterablePromise', Promise, { // .sort(..) // XXX should these support STOP??? map: function(func){ - return this.constructor(this.__list, function(e){ - return [func(e)] }) }, - filter: function(func){ - return this.constructor(this.__list, function(e){ - return func(e) ? - [e] - : [] }) }, - reduce: function(func, res){ return this.constructor(this.__list, function(e){ - res = func(res, e) - return [] }) + return [func(e)] }) }, + filter: function(func){ + return this.constructor(this.__list, + function(e){ + return func(e) ? + [e] + : [] }) }, + reduce: function(func, res){ + return this.constructor(this.__list, + function(e){ + res = func(res, e) + return [] }) .then(function(){ return res }) }, flat: function(depth=1){ - return this.constructor(this.__list, function(e){ - return (e && e.flat) ? - e.flat(depth) - : e }) }, + return this.constructor(this.__list, + function(e){ + return (e && e.flat) ? + e.flat(depth) + : e }) }, // XXX do we need: @@ -173,7 +176,15 @@ object.Constructor('IterablePromise', Promise, { // XXX if list is an iterator, can we fill this async??? // XXX iterator/generator as input: // - do we unwind here or externally? - // ...feels like with the generator external unwinding is needed... + // ...feels like with the generator external unwinding is + // needed... + // XXX would be nice to support trowing STOP... + // - this is more complicated than simply suing .smap(..) instead + // of .map(..) because the list can contain async promises... + // ...would need to wrap each .then(..) call in try-catch and + // manually handle the stop... + // - another issue here is that the stop would happen in order of + // execution and not order of elements... __new__: function(_, list, handler){ var promise @@ -197,6 +208,7 @@ object.Constructor('IterablePromise', Promise, { list = // apply the handler... handler ? + // XXX can we handle STOP here??? list.map(function(block){ return (block instanceof Array ? block diff --git a/README.md b/README.md index afaf597..7ba0a1b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # types.js -A library of JavaScript type extensions, types and type utilities. +Library of JavaScript type extensions, types and utilities. - [types.js](#typesjs) - [Installation](#installation) @@ -128,8 +128,8 @@ A library of JavaScript type extensions, types and type utilities. - [`event.EventMixin`](#eventeventmixin) - [Runner](#runner) - [Micro task queue](#micro-task-queue) - - [`STOP`](#stop) - - [`SKIP`](#skip) + - [`runner.STOP`](#runnerstop) + - [`runner.SKIP`](#runnerskip) - [`Queue(..)` / `Queue.runTasks(..)`](#queue--queueruntasks) - [`Queue.handle(..)`](#queuehandle) - [`.state`](#queuestate) @@ -2299,12 +2299,12 @@ var runner = require('ig-types/runner') This includes [`event.EventMixin`](#eventeventmixin). -#### `STOP` +#### `runner.STOP` -#### `SKIP` +#### `runner.SKIP`