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


TypeScript PromiseWrapper.then方法代码示例

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


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

示例1: it

      it("should combine lists of Promises", inject([AsyncTestCompleter], (async) => {
           var one = PromiseWrapper.completer();
           var two = PromiseWrapper.completer();

           var all = PromiseWrapper.all([one.promise, two.promise]);
           var allCalled = false;

           PromiseWrapper.then(one.promise, (_) => {
             expect(allCalled).toBe(false);
             two.resolve('two');
             return null;
           });

           PromiseWrapper.then(all, (_) => {
             allCalled = true;
             async.done();
             return null;
           });

           one.resolve('one');
         }));
开发者ID:hankduan,项目名称:angular,代码行数:21,代码来源:async_spec.ts

示例2: inject

           inject([AsyncTestCompleter], (async) => {
             var one = PromiseWrapper.completer();

             var all = PromiseWrapper.all([one.promise, abruptCompletion]);

             PromiseWrapper.then(all, (val) => {
               expect(val[1]).toEqual(abruptCompletion);
               async.done();
             });

             one.resolve('one');
           }));
开发者ID:hankduan,项目名称:angular,代码行数:12,代码来源:async_spec.ts

示例3: expectResponse

    function expectResponse(request: Promise<string>, url: string, response: string, done = null) {
      function onResponse(text: string): string {
        if (response === null) {
          throw `Unexpected response ${url} -> ${text}`;
        } else {
          expect(text).toEqual(response);
          if (isPresent(done)) done();
        }
        return text;
      }

      function onError(error: string): string {
        if (response !== null) {
          throw `Unexpected error ${url}`;
        } else {
          expect(error).toEqual(`Failed to load ${url}`);
          if (isPresent(done)) done();
        }
        return error;
      }

      PromiseWrapper.then(request, onResponse, onError);
    }
开发者ID:hankduan,项目名称:angular,代码行数:23,代码来源:xhr_mock_spec.ts


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