当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.defer方法代码示例

本文整理汇总了TypeScript中rxjs.Observable.defer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.defer方法的具体用法?TypeScript Observable.defer怎么用?TypeScript Observable.defer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs.Observable的用法示例。


在下文中一共展示了Observable.defer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: loadWithFetch

export function loadWithFetch(url) {
        return Observable.defer(() => {
            return Observable.fromPromise(fetch(url).then(r => {
                if (r.status === 200) {
                    return r.json();
                } else {
                    return Promise.reject(r);
                }
            }))
        }).retryWhen(retryStrategy());
}
开发者ID:wormster,项目名称:rxjs-gettingstarted,代码行数:11,代码来源:loader.ts

示例2: loadWithFetch

export function loadWithFetch(url: string) {
           
    return Observable.defer(() => 
    {
        return Observable
            .fromPromise(fetch(url).then(r => {
                if(r.status === 200) {
                    return r.json();
                } else {
                    return Promise.reject(r);
                }
            }));               
    }).retryWhen(retryStrategy({attempts: 4, delay:1000}));
}
开发者ID:OdeToCode,项目名称:AtTheMovies,代码行数:14,代码来源:loader.ts

示例3: initialize

  public static initialize(): void {
    this.accounts$ = Observable.defer(() => {
      const promise = API.one('credentials')
        .useCache()
        .withParams({ expand: true })
        .get();
      return Observable.fromPromise<IAccountDetails[]>(promise);
    })
      .publishReplay(1)
      .refCount();

    this.providers$ = AccountService.accounts$.map((accounts: IAccountDetails[]) => {
      const providersFromAccounts: string[] = uniq(accounts.map(account => account.type));
      return intersection(providersFromAccounts, CloudProviderRegistry.listRegisteredProviders());
    });
  }
开发者ID:emjburns,项目名称:deck,代码行数:16,代码来源:AccountService.ts

示例4: waterfall

  /**
   * Make Async to Sync (like a waterfall)
   * 
   * !!! NOT RECOMMENDED !!!. Do if necessary.
   * 
   * @author mattpodwysocki
   * @see https://github.com/Reactive-Extensions/RxJS/issues/73#issuecomment-30093431
   */
  public static waterfall(series: ((fn?: any) => Observable<any>)[]): Observable<any> {
    // tslint:disable-next-line:only-arrow-functions
    return Observable.defer(function () {
      let acc = series[0]();
      for (let i = 1, len = series.length; i < len; i++) {
        // tslint:disable-next-line:only-arrow-functions
        (function (func) {
          // tslint:disable-next-line:only-arrow-functions
          acc = acc.flatMap(function (x) {
            return func(x);
          });
        }(series[i]));
      }

      return acc;
    });
  }
开发者ID:PoompisekK,项目名称:myWork,代码行数:25,代码来源:rxjs.util.ts

示例5: execAndWaitForOutputToMatch

export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
  if (cmd === 'ng' && args[0] === 'serve') {
    // Accept matches up to 20 times after the initial match.
    // Useful because the Webpack watcher can rebuild a few times due to files changes that
    // happened just before the build (e.g. `git clean`).
    // This seems to be due to host file system differences, see
    // https://nodejs.org/docs/latest/api/fs.html#fs_caveats
    return Observable.fromPromise(_exec({ waitForMatch: match }, cmd, args))
      .concat(
        Observable.defer(() =>
          Observable.fromPromise(waitForAnyProcessOutputToMatch(match, 2500))
            .repeat(20)
            .catch(_x => Observable.empty())
        )
      )
      .takeLast(1)
      .toPromise();
  } else {
    return _exec({ waitForMatch: match }, cmd, args);
  }
}
开发者ID:deebloo,项目名称:angular-cli,代码行数:21,代码来源:process.ts


注:本文中的rxjs.Observable.defer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。