ig-types 6.19.0 → 6.20.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/README.md +11 -2
  2. package/generator.js +23 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -111,6 +111,7 @@ Library of JavaScript type extensions, types and utilities.
111
111
  - [`<generator>.shift()` / `<generator>.pop()` / `<generator>.gshift()` / `<generator>.gpop()`](#generatorshift--generatorpop--generatorgshift--generatorgpop)
112
112
  - [`<generator>.unshift(..)` / `<generator>.push(..)`](#generatorunshift--generatorpush)
113
113
  - [`<generator>.join(..)`](#generatorjoin)
114
+ - [`<generator>.unwind(..)`](#generatorunwind)
114
115
  - [`<generator>.then(..)` / `<generator>.catch(..)` / `<generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally)
115
116
  - [`<generator>.toArray()`](#generatortoarray)
116
117
  - [Treating iterators the same as generators](#treating-iterators-the-same-as-generators)
@@ -124,7 +125,7 @@ Library of JavaScript type extensions, types and utilities.
124
125
  - [`<Generator>.between(..)`](#generatorbetween-1)
125
126
  - [`<Generator>.toArray()`](#generatortoarray-1)
126
127
  - [`<Generator>.join(..)`](#generatorjoin-1)
127
- - [`<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`](#generatorthen--generatorcatch--generatorfinally-1)
128
+ - [`<Generator>.unwind(..)`](#generatorunwind-1)
128
129
  - [Generator combinators](#generator-combinators)
129
130
  - [`<Generator>.chain(..)` / `<generator>.chain(..)`](#generatorchain--generatorchain)
130
131
  - [`<Generator>.concat(..)` / `<generator>.concat(..)`](#generatorconcat--generatorconcat)
@@ -136,6 +137,7 @@ Library of JavaScript type extensions, types and utilities.
136
137
  - [`generator.stoppable(..)`](#generatorstoppable)
137
138
  - [Async generator extensions](#async-generator-extensions)
138
139
  - [`generator.AsyncGenerator`](#generatorasyncgenerator)
140
+ - [`<async-generator>.unwind(..)`](#async-generatorunwind)
139
141
  - [`<async-generator>.then(..)` / `<async-generator>.catch(..)` / `<async-generator>.finally(..)`](#async-generatorthen--async-generatorcatch--async-generatorfinally)
140
142
  - [`<async-generator>.iter(..)`](#async-generatoriter)
141
143
  - [`<async-generator>.map(..)` / `<async-generator>.filter(..)` / `<async-generator>.reduce(..)`](#async-generatormap--async-generatorfilter--async-generatorreduce)
@@ -2292,6 +2294,11 @@ _next_ call to `.next()`, regardless of the current generator state.
2292
2294
  XXX
2293
2295
 
2294
2296
 
2297
+ #### `<generator>.unwind(..)`
2298
+
2299
+ XXX
2300
+
2301
+
2295
2302
  #### `<generator>.then(..)` / `<generator>.catch(..)` / `<generator>.finally(..)`
2296
2303
 
2297
2304
  Return a promise and resolve it with the generator value.
@@ -2513,7 +2520,7 @@ Return a function that will return a `<generator>` output as an `Array`.
2513
2520
  XXX
2514
2521
 
2515
2522
 
2516
- #### `<Generator>.then(..)` / `<Generator>.catch(..)` / `<Generator>.finally(..)`
2523
+ #### `<Generator>.unwind(..)`
2517
2524
 
2518
2525
  <!-- XXX -->
2519
2526
 
@@ -2641,6 +2648,8 @@ XXX EXPERIMENTAL
2641
2648
 
2642
2649
  #### `generator.AsyncGenerator`
2643
2650
 
2651
+ #### `<async-generator>.unwind(..)`
2652
+
2644
2653
  #### `<async-generator>.then(..)` / `<async-generator>.catch(..)` / `<async-generator>.finally(..)`
2645
2654
 
2646
2655
  #### `<async-generator>.iter(..)`
package/generator.js CHANGED
@@ -189,11 +189,11 @@ var makeGenerator = function(name, pre){
189
189
  ].join('\n ') }, }) } }
190
190
 
191
191
  // XXX do a better doc...
192
- var makePromise = function(name){
192
+ var makeProxy = function(name){
193
193
  return function(...args){
194
194
  var that = this
195
195
  return function(){
196
- return that(...arguments)[name](func) } } }
196
+ return that(...arguments)[name](...args) } } }
197
197
 
198
198
 
199
199
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -267,9 +267,12 @@ object.Mixin('GeneratorMixin', 'soft', {
267
267
 
268
268
  // promises...
269
269
  //
270
- then: makePromise('then'),
271
- catch: makePromise('catch'),
272
- finally: makePromise('finally'),
270
+ // NOTE: .then(..) and friends are intentionally not defined here to
271
+ // prevent control deadlocks when awaiting for a generator that
272
+ // expects manual unwinding e.g.:
273
+ // g = function*(){}
274
+ // await g // will hang waiting for g to resolve
275
+ unwind: makeProxy('unwind'),
273
276
 
274
277
  // combinators...
275
278
  //
@@ -450,7 +453,8 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
450
453
 
451
454
  // promises...
452
455
  //
453
- then: function(onresolve, onreject){
456
+ // NOTE: this will unwind the generator...
457
+ unwind: function(onresolve, onreject){
454
458
  var that = this
455
459
  var p = new Promise(
456
460
  function(resolve){
@@ -459,10 +463,12 @@ object.Mixin('GeneratorProtoMixin', 'soft', {
459
463
  p.then(...arguments)
460
464
  : p
461
465
  return p },
466
+ then: function(...args){
467
+ return this.unwind(...args) },
462
468
  catch: function(func){
463
- return this.then().catch(func) },
469
+ return this.unwind().catch(...arguments) },
464
470
  finally: function(func){
465
- return this.then().finally(func) },
471
+ return this.unwind.finally(...arguments) },
466
472
 
467
473
  // combinators...
468
474
  //
@@ -531,22 +537,23 @@ object.Mixin('AsyncGeneratorProtoMixin', 'soft', {
531
537
  //
532
538
  // NOTE: this will unwind the generator...
533
539
  // XXX create an iterator promise???
534
- // XXX should we unwind???
535
- then: function(resolve, reject){
540
+ unwind: function(onresolve, onreject){
536
541
  var that = this
537
- var p = new Promise(async function(_resolve, _reject){
542
+ var p = new Promise(async function(resolve){
538
543
  var res = []
539
544
  for await(var elem of that){
540
545
  res.push(elem) }
541
- _resolve(res) })
542
- p = (resolve || reject) ?
546
+ resolve(res) })
547
+ p = (onresolve || onreject) ?
543
548
  p.then(...arguments)
544
549
  : p
545
550
  return p },
551
+ then: function(...args){
552
+ return this.unwind(...args) },
546
553
  catch: function(func){
547
- return this.then().catch(func) },
548
- finally: function(){
549
- return this.then().finally(func) },
554
+ return this.unwind().catch(...arguments) },
555
+ finally: function(func){
556
+ return this.unwind.finally(...arguments) },
550
557
 
551
558
  // XXX might be a good idea to use this approach above...
552
559
  iter: stoppable(async function*(handler=undefined){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ig-types",
3
- "version": "6.19.0",
3
+ "version": "6.20.0",
4
4
  "description": "Generic JavaScript types and type extensions...",
5
5
  "main": "main.js",
6
6
  "scripts": {