some tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-12-08 01:28:01 +03:00
parent e829888c19
commit ac26ca9dcf
2 changed files with 22 additions and 20 deletions

View File

@ -1048,37 +1048,39 @@ object.Mixin('PromiseMixin', 'soft', {
cooperative: CooperativePromise,
sync: SyncPromise,
// XXX should this be implemented via SyncPromise???
// XXX not sure if we need to expand async generators...
awaitOrRun: function(data, func, error){
data = [...arguments]
func = data.pop()
if(typeof(data.at(-1)) == 'function'){
error = func
func = data.pop() }
// ceck if we need to await...
return data
.reduce(function(res, e){
error = error ?
[error]
: []
// check if we need to await...
return 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)
.then(
function(res){
return func(...res) },
...(error ?
[error]
: []))
: data[0].then(
func,
...(error ?
[error]
: [])))
: error ?
// NOTE: we will not reach this on empty data...
(data.length > 1 ?
Promise.all(data)
.then(
function(res){
return func(...res) },
...error)
: data[0].then(func, ...error))
// XXX not sure if we need to expand async generators...
: (data.length == 1
&& Symbol.asyncIterator in data[0]
&& 'then' in data[0]) ?
data[0].then(func, ...error)
: error.length > 0 ?
function(){
try{
return func(...data)
}catch(err){
return error(err) } }()
return error[0](err) } }()
: func(...data) },
})

View File

@ -1,6 +1,6 @@
{
"name": "ig-types",
"version": "6.24.9",
"version": "6.24.10",
"description": "Generic JavaScript types and type extensions...",
"main": "main.js",
"scripts": {