ig-types 6.24.5 → 6.24.7
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 +31 -14
- package/README.md +27 -0
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
var object = require('ig-object')
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
var generator = require('./generator')
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
|
|
@@ -123,18 +123,22 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
123
123
|
// stop will stop the handlers not yet run and not the next
|
|
124
124
|
// handlers in sequence.
|
|
125
125
|
// XXX EXPEREMENTAL: STOP...
|
|
126
|
-
// XXX
|
|
127
|
-
// ...an async generator is not "parallel", i.e. intil one
|
|
128
|
-
// returned promise is resolved the generator blocks (will not
|
|
129
|
-
// advance)...
|
|
130
|
-
// ...can we feed out a results one by one???
|
|
126
|
+
// XXX ITER can we unwind (sync/async) generators one by one???
|
|
131
127
|
__pack: function(list, handler=undefined){
|
|
132
128
|
var that = this
|
|
133
|
-
// handle
|
|
129
|
+
// handle iterator...
|
|
130
|
+
// XXX ITER do we unwind the iterator here or wait to unwind later???
|
|
131
|
+
if(typeof(list) == 'object'
|
|
132
|
+
&& Symbol.iterator in list){
|
|
133
|
+
list = [...list] }
|
|
134
|
+
// handle iterable promise...
|
|
134
135
|
if(list instanceof IterablePromise){
|
|
135
136
|
return this.__handle(list.__packed, handler) }
|
|
136
|
-
// handle promise
|
|
137
|
-
|
|
137
|
+
// handle promise / async-iterator...
|
|
138
|
+
// XXX ITER do we unwind the iterator here or wait to unwind later???
|
|
139
|
+
if(list instanceof Promise
|
|
140
|
+
|| (typeof(list) == 'object'
|
|
141
|
+
&& Symbol.asyncIterator in list)){
|
|
138
142
|
return list.then(function(list){
|
|
139
143
|
return that.__pack(list, handler) }) }
|
|
140
144
|
// do the work...
|
|
@@ -152,6 +156,10 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
152
156
|
var pack = function(){
|
|
153
157
|
return [list].flat()
|
|
154
158
|
[map](function(elem){
|
|
159
|
+
// XXX EXPEREMENTAL -- not sure about this yet...
|
|
160
|
+
//elem = Symbol.iterator in elem ?
|
|
161
|
+
// [...elem]
|
|
162
|
+
// : elem
|
|
155
163
|
// XXX EXPEREMENTAL...
|
|
156
164
|
return elem instanceof IterablePromise ?
|
|
157
165
|
(elem.isSync() ?
|
|
@@ -274,11 +282,16 @@ object.Constructor('IterablePromise', Promise, {
|
|
|
274
282
|
// give up on a sync solution...
|
|
275
283
|
if(e instanceof Promise){
|
|
276
284
|
// XXX can we return an IterablePromise???
|
|
277
|
-
// XXX
|
|
285
|
+
// XXX this will cause infinite recursion....
|
|
278
286
|
//return Promise.iter(list).flat() }
|
|
287
|
+
// XXX is there a more elegant way to do this???
|
|
279
288
|
return Promise.all(list)
|
|
280
289
|
.then(function(list){
|
|
281
|
-
return list.flat() })
|
|
290
|
+
return list.flat() })
|
|
291
|
+
.iter() }
|
|
292
|
+
//return Promise.all(list)
|
|
293
|
+
// .then(function(list){
|
|
294
|
+
// return list.flat() }) }
|
|
282
295
|
res.push(e) }
|
|
283
296
|
return res.flat() },
|
|
284
297
|
/*/
|
|
@@ -1003,10 +1016,9 @@ object.Constructor('SyncPromise', Promise, {
|
|
|
1003
1016
|
// async...
|
|
1004
1017
|
if(!error
|
|
1005
1018
|
&& value instanceof Promise){
|
|
1006
|
-
return value }
|
|
1019
|
+
return object.ASIS(value) }
|
|
1007
1020
|
// sync...
|
|
1008
1021
|
var obj = Promise.resolve(value)
|
|
1009
|
-
obj.__proto__ = this.prototype
|
|
1010
1022
|
obj.value = value
|
|
1011
1023
|
rejected
|
|
1012
1024
|
&& (obj.error = error)
|
|
@@ -1069,7 +1081,12 @@ object.Mixin('PromiseProtoMixin', 'soft', {
|
|
|
1069
1081
|
as: ProxyPromise,
|
|
1070
1082
|
iter: function(handler=undefined){
|
|
1071
1083
|
return IterablePromise(this, handler) },
|
|
1072
|
-
|
|
1084
|
+
// unify the general promise API with other promise types...
|
|
1085
|
+
// XXX should this be here???
|
|
1086
|
+
// XXX error if given must return the result... (???)
|
|
1087
|
+
sync: function(error){
|
|
1088
|
+
typeof(error) == 'function'
|
|
1089
|
+
&& this.catch(error)
|
|
1073
1090
|
return this },
|
|
1074
1091
|
})
|
|
1075
1092
|
|
package/README.md
CHANGED
|
@@ -88,6 +88,9 @@ Library of JavaScript type extensions, types and utilities.
|
|
|
88
88
|
- [Array proxy methods returning `<promise-iter>`](#array-proxy-methods-returning-promise-iter)
|
|
89
89
|
- [Array proxy methods returning a `<promise>`](#array-proxy-methods-returning-a-promise)
|
|
90
90
|
- [`<promise-iter>.then(..)` / `<promise-iter>.catch(..)` / `<promise-iter>.finally(..)`](#promise-iterthen--promise-itercatch--promise-iterfinally)
|
|
91
|
+
- [`<promise-iter>.iterthen(..)`](#promise-iterthen)
|
|
92
|
+
- [`<promise-iter>.isSync(..)`](#promise-issync)
|
|
93
|
+
- [`<promise-iter>.sync(..)`](#promise-sync)
|
|
91
94
|
- [`promise.IterablePromise.STOP` / `promise.IterablePromise.STOP(..)`](#promiseiterablepromisestop--promiseiterablepromisestop)
|
|
92
95
|
- [Advanced handler](#advanced-handler)
|
|
93
96
|
- [Stopping the iteration](#stopping-the-iteration)
|
|
@@ -1823,6 +1826,7 @@ These are similar to [`<array>.some(..)`](https://developer.mozilla.org/en-US/do
|
|
|
1823
1826
|
and [`<array>.find(..)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
|
|
1824
1827
|
see them for more info.
|
|
1825
1828
|
|
|
1829
|
+
|
|
1826
1830
|
#### Array proxy methods returning `<promise-iter>`
|
|
1827
1831
|
|
|
1828
1832
|
- `<promise-iter>.sort(..)`
|
|
@@ -1887,6 +1891,24 @@ For more info see: [Stopping the iteration](#stopping-the-iteration) below, and
|
|
|
1887
1891
|
[the 'Array' STOP section](#arraystop--arraystop)
|
|
1888
1892
|
|
|
1889
1893
|
|
|
1894
|
+
#### `<promise-iter>.iterthen(..)`
|
|
1895
|
+
|
|
1896
|
+
Like `.then(..)` but will return an `IterablePromise` instance.
|
|
1897
|
+
|
|
1898
|
+
|
|
1899
|
+
#### `<promise-iter>.isSync()`
|
|
1900
|
+
|
|
1901
|
+
Return `true` if all content is resolved, otherwise return `false`.
|
|
1902
|
+
|
|
1903
|
+
|
|
1904
|
+
#### `<promise-iter>.sync(..)`
|
|
1905
|
+
|
|
1906
|
+
If all content is resolved return the promise value, otherwise return a promise.
|
|
1907
|
+
|
|
1908
|
+
For more info see: [`<promise>.sync(..)`](#promisesync)
|
|
1909
|
+
|
|
1910
|
+
|
|
1911
|
+
|
|
1890
1912
|
#### Advanced handler
|
|
1891
1913
|
|
|
1892
1914
|
```bnf
|
|
@@ -2008,12 +2030,17 @@ the main `<promise>` is resolved.
|
|
|
2008
2030
|
|
|
2009
2031
|
### Sync/async promise
|
|
2010
2032
|
|
|
2033
|
+
The goal of this is to handle both sync and asynchronous data flows with
|
|
2034
|
+
one promise-like API, if all of the data can be obtained in a sync manner
|
|
2035
|
+
this will be sync otherwise we will revert to a normal promise.
|
|
2036
|
+
|
|
2011
2037
|
|
|
2012
2038
|
#### `Promise.sync(..)` / `promise.SyncPromise(..)`
|
|
2013
2039
|
|
|
2014
2040
|
```dnf
|
|
2015
2041
|
Promise.sync(<func>)
|
|
2016
2042
|
-> <sync-promise>
|
|
2043
|
+
-> <promise>
|
|
2017
2044
|
|
|
2018
2045
|
<func>(<resolve>, <reject>)
|
|
2019
2046
|
|