ig-types 6.22.0 → 6.22.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 +84 -4
- package/README.md +5 -2
- package/package.json +1 -1
package/Promise.js
CHANGED
|
@@ -793,6 +793,65 @@ object.Constructor('ProxyPromise', Promise, {
|
|
|
793
793
|
|
|
794
794
|
|
|
795
795
|
|
|
796
|
+
//---------------------------------------------------------------------
|
|
797
|
+
|
|
798
|
+
// XXX like promise but if a value can be generated sync then this will
|
|
799
|
+
// run in sync otherwise it will fall back to being a promise...
|
|
800
|
+
// ...not sure where to return the sync value...
|
|
801
|
+
// XXX potential problem is recursion (depth) on the sync stage...
|
|
802
|
+
// XXX not sure if we need this..
|
|
803
|
+
var MaybePromice =
|
|
804
|
+
module.MaybePromice =
|
|
805
|
+
object.Constructor('MaybePromise', Promise, {
|
|
806
|
+
// XXX can we get into this without either .__error or .__result ???
|
|
807
|
+
then: function(resolve, reject){
|
|
808
|
+
if(this.hasOwnProperty('__error')){
|
|
809
|
+
return this.constructor.reject(
|
|
810
|
+
reject ?
|
|
811
|
+
reject(this.__error)
|
|
812
|
+
: this.__error) }
|
|
813
|
+
if(this.hasOwnProperty('__result')){
|
|
814
|
+
return this.constructor.resolve(
|
|
815
|
+
resolve(this.__result)) } },
|
|
816
|
+
//catch: function(func){
|
|
817
|
+
//},
|
|
818
|
+
//finally: function(func){
|
|
819
|
+
//},
|
|
820
|
+
|
|
821
|
+
//__error: undefined,
|
|
822
|
+
//__result: undefined,
|
|
823
|
+
__new__: function(context, func){
|
|
824
|
+
var result
|
|
825
|
+
var resolve = function(res){
|
|
826
|
+
result = res }
|
|
827
|
+
var error
|
|
828
|
+
var reject = function(err){
|
|
829
|
+
error = err }
|
|
830
|
+
|
|
831
|
+
try{
|
|
832
|
+
func(resolve, reject)
|
|
833
|
+
}catch(err){
|
|
834
|
+
reject(err) }
|
|
835
|
+
|
|
836
|
+
if(error){
|
|
837
|
+
this.__error = error
|
|
838
|
+
|
|
839
|
+
// async...
|
|
840
|
+
} else if(result instanceof Promise){
|
|
841
|
+
return result }
|
|
842
|
+
|
|
843
|
+
// sync...
|
|
844
|
+
this.__result = result
|
|
845
|
+
// XXX
|
|
846
|
+
var obj = Reflect.construct(
|
|
847
|
+
MaybePromise.__proto__,
|
|
848
|
+
[],
|
|
849
|
+
MaybePromise)
|
|
850
|
+
return obj
|
|
851
|
+
},
|
|
852
|
+
})
|
|
853
|
+
|
|
854
|
+
|
|
796
855
|
//---------------------------------------------------------------------
|
|
797
856
|
|
|
798
857
|
var PromiseMixin =
|
|
@@ -801,10 +860,17 @@ object.Mixin('PromiseMixin', 'soft', {
|
|
|
801
860
|
iter: IterablePromise,
|
|
802
861
|
interactive: InteractivePromise,
|
|
803
862
|
cooperative: CooperativePromise,
|
|
804
|
-
|
|
863
|
+
// XXX
|
|
864
|
+
//maybe: MaybePromise,
|
|
865
|
+
|
|
866
|
+
// XXX need error support...
|
|
805
867
|
awaitOrRun: function(data, func){
|
|
806
868
|
data = [...arguments]
|
|
807
869
|
func = data.pop()
|
|
870
|
+
var error
|
|
871
|
+
if(typeof(data.at(-1)) == 'function'){
|
|
872
|
+
error = func
|
|
873
|
+
func = data.pop() }
|
|
808
874
|
// ceck if we need to await...
|
|
809
875
|
return data
|
|
810
876
|
.reduce(function(res, e){
|
|
@@ -813,9 +879,23 @@ object.Mixin('PromiseMixin', 'soft', {
|
|
|
813
879
|
// NOTE: we will not reach this on empty data...
|
|
814
880
|
(data.length > 1 ?
|
|
815
881
|
Promise.all(data)
|
|
816
|
-
.then(
|
|
817
|
-
|
|
818
|
-
|
|
882
|
+
.then(
|
|
883
|
+
function(res){
|
|
884
|
+
return func(...res) },
|
|
885
|
+
...(error ?
|
|
886
|
+
[error]
|
|
887
|
+
: []))
|
|
888
|
+
: data[0].then(
|
|
889
|
+
func,
|
|
890
|
+
...(error ?
|
|
891
|
+
[error]
|
|
892
|
+
: [])))
|
|
893
|
+
: error ?
|
|
894
|
+
function(){
|
|
895
|
+
try{
|
|
896
|
+
func(...data)
|
|
897
|
+
}catch(err){
|
|
898
|
+
error(err) } }()
|
|
819
899
|
: func(...data) },
|
|
820
900
|
})
|
|
821
901
|
|
package/README.md
CHANGED
|
@@ -2009,12 +2009,15 @@ Await for inputs if any of them is a promise and then run a function with
|
|
|
2009
2009
|
the results, otherwise run the function in sync.
|
|
2010
2010
|
|
|
2011
2011
|
```dnf
|
|
2012
|
-
Promise.awaitOrRun(<value>, <func>)
|
|
2013
|
-
Promise.awaitOrRun(<value>, .. , <func>)
|
|
2012
|
+
Promise.awaitOrRun(<value>, <func>[, <onerror>])
|
|
2013
|
+
Promise.awaitOrRun(<value>, .. , <func>[, <onerror>])
|
|
2014
2014
|
-> <promise(value)>
|
|
2015
2015
|
-> <value>
|
|
2016
2016
|
```
|
|
2017
2017
|
|
|
2018
|
+
Note that if the last `<value>` is a function and no `<onerror>` function
|
|
2019
|
+
is given then `.awaitOrRun(..)` will confuse the `<value>` for `<func>`,
|
|
2020
|
+
to avoid this one needs to explicitly pass `null`/`undefined` as `<onerror>`.
|
|
2018
2021
|
|
|
2019
2022
|
|
|
2020
2023
|
## Generator extensions and utilities
|