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


TypeScript Subscription.add方法代碼示例

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


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

示例1: loadData

  private loadData() {
    this.loadConfig();
    this.loadOrder();

    this.subscription.add(this.walletService.all().subscribe(wallets => {
      this.wallets = wallets;

      if (this.order) {
        this.form.get('wallet').setValue(this.order.filename, { emitEvent: false });
      }
    }));
  }
開發者ID:skycoin,項目名稱:skycoin,代碼行數:12,代碼來源:buy.component.ts

示例2: ngOnInit

  ngOnInit() {
    this.subscriptions = IntervalObservable
      .create(5000)
      .switchMap(() => this.blockchainService.lastBlock())
      .subscribe(block => this.block = block);

    this.subscriptions.add(IntervalObservable
      .create(5000)
      .switchMap(() => this.blockchainService.coinSupply())
      .subscribe(coinSupply => this.coinSupply = coinSupply),
    );
  }
開發者ID:skycoin,項目名稱:skycoin,代碼行數:12,代碼來源:blockchain.component.ts

示例3: findActualExecutable

  let spawnObs = Observable.create((subj: Observer<{
    source: any,
    text: any
    }>) => {
    let { cmd, args } = findActualExecutable(exe, params);
    d(`spawning process: ${cmd} ${args.join()}, ${JSON.stringify(opts)}`);
    let origOpts = assign({}, opts);
    if ('jobber' in origOpts) {
      delete origOpts.jobber;
    }
    if ('split' in origOpts) {
      delete origOpts.split;
    };

    const proc = spawnOg(cmd, args, origOpts);

    let bufHandler = (source: string) => (b: string | Buffer) => {
      if (b.length < 1) {
        return;
      };
      let chunk = '<< String sent back was too long >>';
      try {
        chunk = b.toString();
      } catch (e) {
        chunk = `<< Lost chunk of process output for ${exe} - length was ${b.length}>>`;
      }

      subj.next({ source: source, text: chunk });
    };

    let ret = new Subscription();

    if (opts.stdin) {
      if (proc.stdin) {
        ret.add(opts.stdin.subscribe(
          (x: any) => proc.stdin.write(x),
          subj.error,
          () => proc.stdin.end()
        ));
      } else {
        subj.error(new Error(`opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required`));
      }
    }

    let stderrCompleted: Subject<boolean> | Observable<boolean> | null = null;
    let stdoutCompleted: Subject<boolean> | Observable<boolean> | null = null;
    let noClose = false;

    if (proc.stdout) {
      stdoutCompleted = new AsyncSubject<boolean>();
      proc.stdout.on('data', bufHandler('stdout'));
      proc.stdout.on('close', () => { (stdoutCompleted! as Subject<boolean>).next(true); (stdoutCompleted! as Subject<boolean>).complete(); });
    } else {
      stdoutCompleted = Observable.of(true);
    }

    if (proc.stderr) {
      stderrCompleted = new AsyncSubject<boolean>();
      proc.stderr.on('data', bufHandler('stderr'));
      proc.stderr.on('close', () => { (stderrCompleted! as Subject<boolean>).next(true); (stderrCompleted! as Subject<boolean>).complete(); });
    } else {
      stderrCompleted = Observable.of(true);
    }

    proc.on('error', (e: Error) => {
      noClose = true;
      subj.error(e);
    });

    proc.on('close', (code: number) => {
      noClose = true;
      let pipesClosed = Observable.merge(stdoutCompleted!, stderrCompleted!)
        .reduce((acc) => acc, true);

      if (code === 0) {
        pipesClosed.subscribe(() => subj.complete());
      } else {
        pipesClosed.subscribe(() => subj.error(new Error(`Failed with exit code: ${code}`)));
      }
    });

    ret.add(new Subscription(() => {
      if (noClose) {
        return;
      };

      d(`Killing process: ${cmd} ${args.join()}`);
      if (opts.jobber) {
        // NB: Connecting to Jobber's named pipe will kill it
        net.connect(`\\\\.\\pipe\\jobber-${proc.pid}`);
        setTimeout(() => proc.kill(), 5 * 1000);
      } else {
        proc.kill();
      }
    }));

    return ret;
  });
開發者ID:d0f,項目名稱:.vscode,代碼行數:98,代碼來源:index.ts

示例4: addTo

export function addTo(collectorSub: Subscription): void {
  collectorSub.add(this);
}
開發者ID:BrainCrumbz,項目名稱:ng2-autocomplete-words-example,代碼行數:3,代碼來源:addTo.ts


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