Comparing version 1.1.2 to 1.1.3
@@ -95,3 +95,2 @@ import { TYPE } from './effects'; | ||
const subscribers = new Set(); | ||
let cancel; | ||
@@ -121,3 +120,3 @@ const onConclude = (error, result) => { | ||
cancel = runners.get(flowType)(it, onConclude); | ||
const cancel = runners.get(flowType)(it, onConclude); | ||
@@ -164,8 +163,12 @@ return unsubscribe; | ||
function runIterator(it, callback) { | ||
let cancel; | ||
let cancel, step = 0; | ||
const setCancel = (j, fn) => { | ||
if (j >= step) cancel = fn; | ||
} | ||
function iterate(error, result) { | ||
try { | ||
let cancelled = false; | ||
cancel = () => cancelled = true; | ||
setCancel(++step, () => cancelled = true); | ||
@@ -178,3 +181,3 @@ const { value, done } = error | ||
cancel = conclude(value, done ? callback : iterate); | ||
setCancel(step, conclude(value, done ? callback : iterate)); | ||
} | ||
@@ -181,0 +184,0 @@ catch (err) { |
{ | ||
"name": "conclure", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Generator runner", | ||
@@ -5,0 +5,0 @@ "main": "conclude.js", |
import test from 'ava'; | ||
import { conclude, inProgress, getResult } from '../conclude'; | ||
import { conclude, inProgress, getResult, whenFinished } from '../conclude'; | ||
import { delay, call } from '../effects'; | ||
@@ -89,1 +89,22 @@ import * as Conclude from '../combinators'; | ||
}); | ||
test.cb('all, cancelling before completion', t => { | ||
const promises = [ | ||
Promise.resolve(42), | ||
Promise.reject('boom') | ||
]; | ||
function* g() { | ||
yield 5; | ||
yield Conclude.all(promises); | ||
} | ||
const cancel = conclude(g(), t.fail); | ||
let count = 2; | ||
whenFinished(promises[0], ({ cancelled }) => cancelled && --count === 0 && t.end(null)); | ||
whenFinished(promises[1], ({ cancelled }) => cancelled && --count === 0 && t.end(null)); | ||
cancel(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28843
598