mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
added Promise.awaitOrRun(..)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d64b1f069a
commit
07f8dfcb29
16
Promise.js
16
Promise.js
@ -801,6 +801,22 @@ object.Mixin('PromiseMixin', 'soft', {
|
||||
iter: IterablePromise,
|
||||
interactive: InteractivePromise,
|
||||
cooperative: CooperativePromise,
|
||||
|
||||
awaitOrRun: function(data, func){
|
||||
data = [...arguments]
|
||||
func = data.pop()
|
||||
// ceck 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) })
|
||||
: data[0].then(func))
|
||||
: func(...data) },
|
||||
})
|
||||
|
||||
PromiseMixin(Promise)
|
||||
|
||||
18
README.md
18
README.md
@ -94,6 +94,8 @@ Library of JavaScript type extensions, types and utilities.
|
||||
- [Promise proxies](#promise-proxies)
|
||||
- [`<promise>.as(..)`](#promiseas)
|
||||
- [`<promise-proxy>.<method>(..)`](#promise-proxymethod)
|
||||
- [Promise utilities](#promise-utilities)
|
||||
- [`Promise.awaitOrRun(..)`](#promiseawaitorrun)
|
||||
- [Generator extensions and utilities](#generator-extensions-and-utilities)
|
||||
- [The basics](#the-basics)
|
||||
- [`generator.Generator`](#generatorgenerator)
|
||||
@ -1999,6 +2001,22 @@ the main `<promise>` is resolved.
|
||||
|
||||
|
||||
|
||||
### Promise utilities
|
||||
|
||||
#### `Promise.awaitOrRun(..)`
|
||||
|
||||
Await for inputs if any of them is a promise and then run a function with
|
||||
the results, otherwise run the function in sync.
|
||||
|
||||
```dnf
|
||||
Promise.awaitOrRun(<value>, <func>)
|
||||
Promise.awaitOrRun(<value>, .. , <func>)
|
||||
-> <promise(value)>
|
||||
-> <value>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Generator extensions and utilities
|
||||
|
||||
```javascript
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-types",
|
||||
"version": "6.21.0",
|
||||
"version": "6.22.0",
|
||||
"description": "Generic JavaScript types and type extensions...",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user