kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

Do I need to unsubscribe a listener to a stream that ends in Kefir? #182

Closed frankandrobot closed 8 years ago

frankandrobot commented 8 years ago
const oneTimeStream = Kefir.constant('foo') // this ends after firing foo
const listener = function() { //... }

oneTimeStream.onValue(listener)
// do I need to unsubscribe #listener?

Does Kefir automagically unsubscribe listeners when the stream ends or do you still need to manually unsubscribe them?

rpominov commented 8 years ago

Yeah, you don't need to. All listeners automatically removed on end. Also when you subscribe to an ended stream it's a noop.

Btw, because of that you can often avoid manual unsubscribing by limiting stream with take/takeWhile/takeUntilBy/etc.

stream.take(1).onValue(fn)
frankandrobot commented 8 years ago

Nice!