rxjsで購読を止める
色々やり方はあると思うが一つ聞いたのはこういうもの。
const root = new BehaviorSubject<"start"|"end">("start"); const subject = new Subject<string>(); const op = root.pipe(mergeMap((x) => { if (x == "end") { return throwError(new Error("end")); } return subject; })).pipe() op.subscribe((x) => { console.log("1:"+x); },(e) => { console.log("1:"+e); }) subject.next("a"); subject.next("b"); root.next("end"); root.next("start"); op.subscribe((x) => { console.log("2:"+x); },(e) => { console.log("2:"+e); }) subject.next("c"); subject.next("d"); root.next("end"); root.next("start"); subject.next("e"); subject.next("f"); /* 1:a 1:b 1:Error: end 2:c 2:d 2:Error: end */