-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rstream): MetaStream close mode handling
- never go into DONE state if `closeIn == CloseMode.NEVER` - fix/update unsubscribe() & pass arg - update detach() to consider `closeOut` mode - add tests
- Loading branch information
1 parent
d177553
commit 2d9e907
Showing
2 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as assert from "assert"; | ||
import { CloseMode, fromIterable, metaStream, State } from "../src/index"; | ||
import { TIMEOUT } from "./config"; | ||
|
||
describe("MetaStream", () => { | ||
it("basic", (done) => { | ||
const src = fromIterable([1, 2, 3], { delay: TIMEOUT }); | ||
const meta = metaStream<number, number>((x) => | ||
fromIterable([x * 10, x * 20, x * 30], { delay: TIMEOUT >> 2 }) | ||
); | ||
const sub = src.subscribe(meta); | ||
const acc: number[] = []; | ||
const sub2 = sub.subscribe({ | ||
next(x) { | ||
acc.push(x); | ||
}, | ||
}); | ||
setTimeout(() => { | ||
assert.deepEqual(acc, [10, 20, 30, 20, 40, 60, 30, 60, 90]); | ||
assert.equal(meta.getState(), State.DONE); | ||
assert.equal(sub.getState(), State.DONE); | ||
assert.equal(sub2.getState(), State.DONE); | ||
done(); | ||
}, 5 * TIMEOUT); | ||
}); | ||
|
||
it("closein", (done) => { | ||
const src = fromIterable([1], { delay: TIMEOUT }); | ||
const meta = metaStream((x) => fromIterable([x]), { | ||
closeIn: CloseMode.NEVER, | ||
}); | ||
const sub = src.subscribe(meta); | ||
const child = sub.subscribe({ | ||
next(x) { | ||
console.log(x); | ||
}, | ||
}); | ||
setTimeout(() => { | ||
assert.equal(src.getState(), State.DONE); | ||
assert.equal(meta.getState(), State.ACTIVE); | ||
assert.equal(sub.getState(), State.ACTIVE); | ||
assert.equal(child.getState(), State.IDLE); | ||
done(); | ||
}, 3 * TIMEOUT); | ||
}); | ||
|
||
it("closeout", (done) => { | ||
const src = fromIterable([1], { delay: TIMEOUT }); | ||
const meta = src.subscribe( | ||
metaStream((x) => fromIterable([x * 10]), { | ||
closeIn: CloseMode.NEVER, | ||
closeOut: CloseMode.NEVER, | ||
}) | ||
); | ||
const acc: number[] = []; | ||
const child = meta.subscribe({ | ||
next(x) { | ||
acc.push(x); | ||
}, | ||
}); | ||
setTimeout(() => { | ||
child.unsubscribe(); | ||
assert.equal(src.getState(), State.DONE); | ||
assert.equal(meta.getState(), State.ACTIVE); | ||
meta.subscribe({ | ||
next(x) { | ||
acc.push(x); | ||
}, | ||
}); | ||
assert.deepEqual(acc, [10, 10]); | ||
done(); | ||
}, 3 * TIMEOUT); | ||
}); | ||
}); |