callbag-from-iter
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -9,6 +9,7 @@ const fromIter = iter => (start, sink) => { | ||
let got1 = false; | ||
let completed = false; | ||
let res; | ||
function loop() { | ||
inloop = true; | ||
while (got1) { | ||
while (got1 && !completed) { | ||
got1 = false; | ||
@@ -22,5 +23,9 @@ res = iterator.next(); | ||
sink(0, t => { | ||
if (completed) return | ||
if (t === 1) { | ||
got1 = true; | ||
if (!inloop && !(res && res.done)) loop(); | ||
} else if (t === 2) { | ||
completed = true; | ||
} | ||
@@ -27,0 +32,0 @@ }); |
{ | ||
"name": "callbag-from-iter", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Convert an iterable or iterator to a callbag pullable source", | ||
@@ -15,3 +15,5 @@ "repository": { | ||
"license": "MIT", | ||
"keywords": ["callbag"], | ||
"keywords": [ | ||
"callbag" | ||
], | ||
"devDependencies": { | ||
@@ -18,0 +20,0 @@ "tape": "^4.8.0" |
32
test.js
@@ -98,1 +98,33 @@ const test = require('tape'); | ||
}); | ||
test('it stops sending after source completion', t => { | ||
t.plan(5); | ||
const source = fromIter([10, 20, 30]); | ||
const actual = []; | ||
const downwardsExpectedTypes = [ | ||
[0, 'function'], | ||
[1, 'number'], | ||
]; | ||
let talkback; | ||
source(0, (type, data) => { | ||
const et = downwardsExpectedTypes.shift(); | ||
t.equals(type, et[0], 'downwards type is expected: ' + et[0]); | ||
t.equals(typeof data, et[1], 'downwards data type is expected: ' + et[1]); | ||
if (type === 0) { | ||
talkback = data; | ||
talkback(1); | ||
return; | ||
} | ||
if (type === 1) { | ||
actual.push(data); | ||
talkback(2); | ||
talkback(1); | ||
talkback(1); | ||
} | ||
}); | ||
t.deepEquals(actual, [10]); | ||
}); |
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
6129
145