mithril.js
mithril.js copied to clipboard
Dependent streams should end when their parent ends
Expected Behavior
const s = Stream()
const c = stream.map(a => a)
s.end.map(() => console.log('parent ended'))
c.end.map(() => console.log('child ended'))
stream.end(true) // logs "parent ended" and "child ended"
Current Behavior
const s = Stream()
const c = stream.map(a => a)
s.end.map(() => console.log('parent ended'))
c.end.map(() => console.log('child ended'))
stream.end(true) // logs just "parent ended"
Possible Solution
Potentially something down the vein of this comment by @pygy, but it may need altered.
Context
I created this issue to track the issue reported in #2030 (a heavily outdated PR targeting the wrong branch).
Note that the idea here is to close dependent streams after all parent streams close. Things like .map
and scan
of course only have one, but things like combine
would wait for all parent streams to close first before ~~terminating~~ Edit: closing their dependents.
My 50 cents: in Rx stream is closed when it receives Completed event so basically when any of the parent streams are closed flatMap
and similar operators swallow inner Completed events of course). While I'm sure they did it for their own reasons, it can be quite confusing, especially in some UI code: hunting down that closed stream can be a pain (considering the same applies for errors).