ig-types 6.23.0 → 6.24.1
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 +20 -10
- package/README.md +37 -7
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -799,24 +799,27 @@ object.Constructor('ProxyPromise', Promise, {
|
|
|
799
799
|
// XXX DOCS...
|
|
800
800
|
// XXX like promise but if a value can be generated sync then this will
|
|
801
801
|
// run in sync otherwise it will fall back to being a promise...
|
|
802
|
-
// XXX
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
object.Constructor('MaybePromise', Promise, {
|
|
807
|
-
//error: undefined,
|
|
802
|
+
// XXX should we throw errors in sync mode??? ...option???
|
|
803
|
+
var SyncPromise =
|
|
804
|
+
module.SyncPromise =
|
|
805
|
+
object.Constructor('SyncPromise', Promise, {
|
|
808
806
|
//value: undefined,
|
|
807
|
+
//error: undefined,
|
|
809
808
|
|
|
809
|
+
// NOTE: if this is called it means that .__new__(..) returned in sync
|
|
810
|
+
// mode and thus set .value and possibly .error, soe there is no
|
|
811
|
+
// need to check for .value...
|
|
810
812
|
then: function(resolve, reject){
|
|
811
813
|
if(this.hasOwnProperty('error')){
|
|
812
814
|
return this.constructor.reject(
|
|
813
815
|
reject ?
|
|
814
816
|
reject(this.error)
|
|
815
817
|
: this.error) }
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
resolve(this.value)) } },
|
|
818
|
+
return this.constructor.resolve(
|
|
819
|
+
resolve(this.value)) },
|
|
819
820
|
|
|
821
|
+
// NOTE: if func calls resolve(..) with a promise then this will return
|
|
822
|
+
// that promise...
|
|
820
823
|
__new__: function(context, func){
|
|
821
824
|
var result
|
|
822
825
|
var resolve = function(res){
|
|
@@ -854,7 +857,7 @@ object.Mixin('PromiseMixin', 'soft', {
|
|
|
854
857
|
interactive: InteractivePromise,
|
|
855
858
|
cooperative: CooperativePromise,
|
|
856
859
|
// XXX EXPEREMENTAL...
|
|
857
|
-
|
|
860
|
+
sync: SyncPromise,
|
|
858
861
|
|
|
859
862
|
// XXX need error support...
|
|
860
863
|
awaitOrRun: function(data, func){
|
|
@@ -901,6 +904,13 @@ object.Mixin('PromiseProtoMixin', 'soft', {
|
|
|
901
904
|
as: ProxyPromise,
|
|
902
905
|
iter: function(handler=undefined){
|
|
903
906
|
return IterablePromise(this, handler) },
|
|
907
|
+
// XXX revise...
|
|
908
|
+
sync: function(){
|
|
909
|
+
if(this instanceof SyncPromise){
|
|
910
|
+
if('error' in this){
|
|
911
|
+
throw this.error }
|
|
912
|
+
return this.value }
|
|
913
|
+
return this },
|
|
904
914
|
})
|
|
905
915
|
|
|
906
916
|
PromiseProtoMixin(Promise.prototype)
|
package/README.md
CHANGED
|
@@ -94,9 +94,10 @@ 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
|
-
- [Sync/
|
|
98
|
-
- [`Promise.
|
|
99
|
-
- [`<
|
|
97
|
+
- [Sync/async promise](#syncasync-promise)
|
|
98
|
+
- [`Promise.sync(..)` / `promise.SyncPromice(..)`](#promisesync--promisesyncpromice)
|
|
99
|
+
- [`<promise>.sync(..)`](#promisesync)
|
|
100
|
+
- [`<sync-promise>.value` / `<sync-promise>.error`](#sync-promisevalue--sync-promiseerror)
|
|
100
101
|
- [Promise utilities](#promise-utilities)
|
|
101
102
|
- [`Promise.awaitOrRun(..)`](#promiseawaitorrun)
|
|
102
103
|
- [Generator extensions and utilities](#generator-extensions-and-utilities)
|
|
@@ -2007,13 +2008,42 @@ the main `<promise>` is resolved.
|
|
|
2007
2008
|
### Sync/async promise
|
|
2008
2009
|
|
|
2009
2010
|
|
|
2010
|
-
#### `Promise.
|
|
2011
|
+
#### `Promise.sync(..)` / `promise.SyncPromice(..)`
|
|
2011
2012
|
|
|
2012
|
-
|
|
2013
|
+
```dnf
|
|
2014
|
+
Promise.sync(<func>)
|
|
2015
|
+
-> <sync-promise>
|
|
2013
2016
|
|
|
2014
|
-
|
|
2017
|
+
<func>(<resolve>, <reject>)
|
|
2018
|
+
|
|
2019
|
+
<resolve>(<value>)
|
|
2020
|
+
|
|
2021
|
+
<reject>(<error>)
|
|
2022
|
+
```
|
|
2023
|
+
|
|
2024
|
+
Implements the full `Promise` protocol but does it in a sync manner, but
|
|
2025
|
+
the execution of `<func>` is done synchronously. If the value passed to
|
|
2026
|
+
`<resolve>(..)` is a promise this will return that and continue asynchronously
|
|
2027
|
+
otherwise all the promise API (`.then(..)`/`.catch(..)`/...) is run in sync.
|
|
2028
|
+
|
|
2029
|
+
<!--
|
|
2030
|
+
Example:
|
|
2031
|
+
```javascript
|
|
2032
|
+
```
|
|
2033
|
+
-->
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
#### `<promise>.sync()`
|
|
2037
|
+
|
|
2038
|
+
Synchronously return the resolved value if `<sync-promise>` resolved, and
|
|
2039
|
+
if it _rejected_ then re-throw the `<error>`.
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
#### `<sync-promise>.value` / `<sync-promise>.error`
|
|
2043
|
+
|
|
2044
|
+
`<sync-promise>` attributes that provide access the resolved `.value` and/or
|
|
2045
|
+
rejection `.error`.
|
|
2015
2046
|
|
|
2016
|
-
XXX
|
|
2017
2047
|
|
|
2018
2048
|
|
|
2019
2049
|
### Promise utilities
|