From 022c12d81e307510cdd6055952a02d9edbac1b62 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 11 Feb 2023 23:16:31 +0300 Subject: [PATCH] Promise.awaitOrRun(..) now accepts null in place of the error handler... Signed-off-by: Alex A. Naanou --- Promise.js | 20 ++++++++++++++++---- package.json | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Promise.js b/Promise.js index d9ca0d2..7e3bdea 100644 --- a/Promise.js +++ b/Promise.js @@ -1359,22 +1359,34 @@ object.Mixin('PromiseMixin', 'soft', { sync: SyncPromise, + // + // .awaitOrRun(, .. , ) + // .awaitOrRun(, .. , , ) + // .awaitOrRun(, .. , , null) + // -> + // -> + // // XXX should this be implemented via SyncPromise??? // XXX not sure if we need to expand async generators... // (update README if this changes) + // XXX add ability to skip array internals checking... awaitOrRun: function(data, func, error){ + var mode = 'deep' data = [...arguments] func = data.pop() - if(typeof(data.at(-1)) == 'function'){ + if(data.length > 1 + && (typeof(data.at(-1)) == 'function' + || func == null)){ error = func func = data.pop() } error = error ? [error] : [] // check if we need to await... - return data.reduce(function(res, e){ - return res - || e instanceof Promise }, false) ? + return (mode == 'deep' + && data.reduce(function(res, e){ + return res + || e instanceof Promise }, false)) ? // NOTE: we will not reach this on empty data... (data.length > 1 ? Promise.all(data) diff --git a/package.json b/package.json index b97070d..b3074ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-types", - "version": "6.26.0", + "version": "6.26.1", "description": "Generic JavaScript types and type extensions...", "main": "main.js", "scripts": {