Closed alshdavid closed 1 year ago
If you use the start
event, you can do that :
const source$ = new Observable(o => setInterval(o.next, 1000))
// Will unsubscribe after first event has been emitted
source$.subscribe({
start(sub) {this.sub = sub},
next(i) => {
console.log(i * 2);
this.sub.unsubscribe();
}
})
I think an elegant way to manage self un-subscriptions is by seeing if a subscriber returns a cancelation token.
The token can be a static property on the
Subscription
class.This will allow for simple community driven "operator" functionality