Get all current (active) subscriptions

后端 未结 7 1115
清歌不尽
清歌不尽 2021-02-12 20:58

Is it possible to get all the \"active\" subscriptions without storing them manually?

I\'d like to unsubscribe all of the \"active\" subscriptions and don\'

相关标签:
7条回答
  • 2021-02-12 21:48

    One of the options is to use takeUntil in combination with Subject to stop all (Observable) subscriptions.

    terminator$: Subject<boolean> = new Subject();
    
    Observable.timer(1000)
      .do(i => console.log(`timer 1: ${i}`))
      .takeUntil(terminator$)
      .subscribe();
    
    Observable.timer(5000)
      .do(i => console.log(`timer 2: ${i}`))
      .takeUntil(terminator$)
      .subscribe();
    
    const stopSubscriptions = () => terminator$.next(true);
    
    0 讨论(0)
提交回复
热议问题