RxJS - 多播运算符 publishLast
publishBehaviour 使用 AsyncSubject,并返回 ConnectableObservable。必须使用 connect() 方法订阅所创建的可观测对象。
示例
import { interval } from 'rxjs'; import { take, publishLast} from 'rxjs/operators'; let observer = interval(1000).pipe( take(10), publishLast() ); const subscribe_one = observer.subscribe( x => console.log("Value from Sub1 = "+x) ); const subscribe_two = observer.subscribe( x => console.log("Value from Sub2 = "+x) ); observer.connect();
输出
广告