當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.subscribeOnCompleted方法代碼示例

本文整理匯總了TypeScript中rx.Observable.subscribeOnCompleted方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.subscribeOnCompleted方法的具體用法?TypeScript Observable.subscribeOnCompleted怎麽用?TypeScript Observable.subscribeOnCompleted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.Observable的用法示例。


在下文中一共展示了Observable.subscribeOnCompleted方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: matchEvents

      return Observable.create((observer: Observer<Object>) => {
        const match = events ? matchEvents(events) : null;
        const bag = new CompositeDisposable();
        const observerables: Observable<any>[] = values(tasks);

        let s1: Observable<any>;
        let connectables: ConnectableObservable<any>[];
        let readyActionObservables: Observable<{type: 'ready'}>[];

        if (observerables.length) {
          connectables = observerables.map((s) => s.publish());
          readyActionObservables =
            connectables.map((s) => s.filter(propEq('type', 'ready')));

          const allParentsReady: Observable<{type: 'ready'}[]> =
            Observable.combineLatest.apply(null, readyActionObservables).take(1);

          s1 = allParentsReady;
        } else {
          s1 = Observable.just(null);
        }

        if (preStart) {
          s1 = s1.flatMap(() => spawn(preStart));

          if (match) {
            s1 = s1.doOnNext((val: string) => {
              const action = match(val);
              if (action) {
                observer.onNext(action);
              }
            });
          }
        }

        let input: EventEmitter;
        let output: EventEmitter;

        bag.add(s1.subscribeOnCompleted(() => {
          if (start) {
            let s2: Observable<string>;

            if (readyActionObservables) {
              s2 = Observable
                .merge
                .apply(null, readyActionObservables)
                .startWith(null)
                .flatMapLatest(() => spawn(start));
            } else {
              s2 = spawn(start);
            }

            let d: Disposable;

            if (match) {
              d = s2.subscribeOnNext((val) => {
                const action = match(val);
                if (action) {
                  observer.onNext(action);
                }
              });
            } else {
              d = s2.subscribe(() => {});
            }

            bag.add(d);
          } else { // "process"
            input = new EventEmitter();
            output = new EventEmitter();

            output.on('action', (obj: Object) => {
              observer.onNext(obj);
            });

            process(input, output);

            const d = Observable.merge.apply(null, connectables)
              .subscribeOnNext((action: Object) => input.emit('action', action));

            bag.add(d);
          }
        }));

        if (connectables) {
          connectables.forEach((s) => bag.add(s.connect()));
        }

        return () => {
          bag.dispose();
          if (input) {
            input.removeAllListeners();
          }
          if (output) {
            output.removeAllListeners();
          }
        };
      });
開發者ID:d6u,項目名稱:dev-runner,代碼行數:97,代碼來源:utils.ts


注:本文中的rx.Observable.subscribeOnCompleted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。