ig-types 6.22.2 → 6.24.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.
Files changed (3) hide show
  1. package/Promise.js +40 -37
  2. package/README.md +19 -0
  3. package/package.json +1 -1
package/Promise.js CHANGED
@@ -795,60 +795,56 @@ object.Constructor('ProxyPromise', Promise, {
795
795
 
796
796
  //---------------------------------------------------------------------
797
797
 
798
+ // XXX EXPEREMENTAL...
799
+ // XXX DOCS...
798
800
  // XXX like promise but if a value can be generated sync then this will
799
801
  // 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 ???
802
+ // XXX should we throw errors in sync mode??? ...option???
803
+ var SyncPromise =
804
+ module.SyncPromise =
805
+ object.Constructor('SyncPromise', Promise, {
806
+ //value: undefined,
807
+ //error: undefined,
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...
807
812
  then: function(resolve, reject){
808
- if(this.hasOwnProperty('__error')){
813
+ if(this.hasOwnProperty('error')){
809
814
  return this.constructor.reject(
810
815
  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,
816
+ reject(this.error)
817
+ : this.error) }
818
+ return this.constructor.resolve(
819
+ resolve(this.value)) },
820
+
821
+ // NOTE: if func calls resolve(..) with a promise then this will return
822
+ // that promise...
823
823
  __new__: function(context, func){
824
824
  var result
825
825
  var resolve = function(res){
826
826
  result = res }
827
+ var rejected
827
828
  var error
828
829
  var reject = function(err){
830
+ rejected = true
829
831
  error = err }
830
-
832
+ // call...
831
833
  try{
832
834
  func(resolve, reject)
833
835
  }catch(err){
834
836
  reject(err) }
835
-
836
- if(error){
837
- this.__error = error
838
-
839
837
  // async...
840
- } else if(result instanceof Promise){
838
+ if(!error
839
+ && result instanceof Promise){
841
840
  return result }
842
-
843
841
  // sync...
844
- this.__result = result
845
- // XXX
846
- var obj = Reflect.construct(
847
- MaybePromise.__proto__,
848
- [],
849
- MaybePromise)
850
- return obj
851
- },
842
+ var obj = Promise.resolve(result)
843
+ obj.__proto__ = this.prototype
844
+ obj.value = result
845
+ rejected
846
+ && (obj.error = error)
847
+ return obj },
852
848
  })
853
849
 
854
850
 
@@ -860,8 +856,8 @@ object.Mixin('PromiseMixin', 'soft', {
860
856
  iter: IterablePromise,
861
857
  interactive: InteractivePromise,
862
858
  cooperative: CooperativePromise,
863
- // XXX
864
- //maybe: MaybePromise,
859
+ // XXX EXPEREMENTAL...
860
+ sync: SyncPromise,
865
861
 
866
862
  // XXX need error support...
867
863
  awaitOrRun: function(data, func){
@@ -908,6 +904,13 @@ object.Mixin('PromiseProtoMixin', 'soft', {
908
904
  as: ProxyPromise,
909
905
  iter: function(handler=undefined){
910
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 },
911
914
  })
912
915
 
913
916
  PromiseProtoMixin(Promise.prototype)
package/README.md CHANGED
@@ -94,6 +94,9 @@ 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/async promise](#syncasync-promise)
98
+ - [`Promise.maybe(..)` / `promise.MaybePromice(..)`](#promisemaybe--promisemaybepromice)
99
+ - [`<maybe-promise>.value` / `<maybe-promise>.error`](#maybe-promisevalue--maybe-promiseerror)
97
100
  - [Promise utilities](#promise-utilities)
98
101
  - [`Promise.awaitOrRun(..)`](#promiseawaitorrun)
99
102
  - [Generator extensions and utilities](#generator-extensions-and-utilities)
@@ -2001,6 +2004,22 @@ the main `<promise>` is resolved.
2001
2004
 
2002
2005
 
2003
2006
 
2007
+ ### Sync/async promise
2008
+
2009
+
2010
+ #### `Promise.sync(..)` / `promise.SyncPromice(..)`
2011
+
2012
+ XXX
2013
+
2014
+ #### `<sync-promise>.value` / `<sync-promise>.error`
2015
+
2016
+ XXX
2017
+
2018
+ #### `<promise>.sync()`
2019
+
2020
+ XXX
2021
+
2022
+
2004
2023
  ### Promise utilities
2005
2024
 
2006
2025
  #### `Promise.awaitOrRun(..)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.22.2",
3
+ "version": "6.24.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {