ig-types 6.21.0 → 6.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Promise.js +16 -0
- package/README.md +25 -1
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -801,6 +801,22 @@ object.Mixin('PromiseMixin', 'soft', {
|
|
|
801
801
|
iter: IterablePromise,
|
|
802
802
|
interactive: InteractivePromise,
|
|
803
803
|
cooperative: CooperativePromise,
|
|
804
|
+
|
|
805
|
+
awaitOrRun: function(data, func){
|
|
806
|
+
data = [...arguments]
|
|
807
|
+
func = data.pop()
|
|
808
|
+
// ceck if we need to await...
|
|
809
|
+
return data
|
|
810
|
+
.reduce(function(res, e){
|
|
811
|
+
return res
|
|
812
|
+
|| e instanceof Promise }, false) ?
|
|
813
|
+
// NOTE: we will not reach this on empty data...
|
|
814
|
+
(data.length > 1 ?
|
|
815
|
+
Promise.all(data)
|
|
816
|
+
.then(function(res){
|
|
817
|
+
return func(...res) })
|
|
818
|
+
: data[0].then(func))
|
|
819
|
+
: func(...data) },
|
|
804
820
|
})
|
|
805
821
|
|
|
806
822
|
PromiseMixin(Promise)
|
package/README.md
CHANGED
|
@@ -94,6 +94,8 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
94
94
|
- [Promise proxies](#promise-proxies)
|
|
95
95
|
- [`<promise>.as(..)`](#promiseas)
|
|
96
96
|
- [`<promise-proxy>.<method>(..)`](#promise-proxymethod)
|
|
97
|
+
- [Promise utilities](#promise-utilities)
|
|
98
|
+
- [`Promise.awaitOrRun(..)`](#promiseawaitorrun)
|
|
97
99
|
- [Generator extensions and utilities](#generator-extensions-and-utilities)
|
|
98
100
|
- [The basics](#the-basics)
|
|
99
101
|
- [`generator.Generator`](#generatorgenerator)
|
|
@@ -636,11 +638,17 @@ Compare to arrays ignoring element order and count.
|
|
|
636
638
|
Sort array as a different array.
|
|
637
639
|
```bnf
|
|
638
640
|
<array>.sortAs(<other>)
|
|
641
|
+
<array>.sortAs(<other>, 'head')
|
|
642
|
+
-> <array>
|
|
643
|
+
|
|
644
|
+
<array>.sortAs(<other>, 'tail')
|
|
639
645
|
-> <array>
|
|
640
646
|
```
|
|
641
647
|
|
|
642
648
|
Elements not present in `<other>` retain their relative order and are
|
|
643
|
-
placed after the sorted elements.
|
|
649
|
+
placed after the sorted elements if `'head'` (i.e. _"sorted at head of
|
|
650
|
+
array"_) is passed as second argument (default) and before them if
|
|
651
|
+
`'tail'` (_"sorted at tail"_) is passed.
|
|
644
652
|
|
|
645
653
|
Example:
|
|
646
654
|
```javascript
|
|
@@ -1993,6 +2001,22 @@ the main `<promise>` is resolved.
|
|
|
1993
2001
|
|
|
1994
2002
|
|
|
1995
2003
|
|
|
2004
|
+
### Promise utilities
|
|
2005
|
+
|
|
2006
|
+
#### `Promise.awaitOrRun(..)`
|
|
2007
|
+
|
|
2008
|
+
Await for inputs if any of them is a promise and then run a function with
|
|
2009
|
+
the results, otherwise run the function in sync.
|
|
2010
|
+
|
|
2011
|
+
```dnf
|
|
2012
|
+
Promise.awaitOrRun(<value>, <func>)
|
|
2013
|
+
Promise.awaitOrRun(<value>, .. , <func>)
|
|
2014
|
+
-> <promise(value)>
|
|
2015
|
+
-> <value>
|
|
2016
|
+
```
|
|
2017
|
+
|
|
2018
|
+
|
|
2019
|
+
|
|
1996
2020
|
## Generator extensions and utilities
|
|
1997
2021
|
|
|
1998
2022
|
```javascript
|