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


TypeScript Promise.all方法代碼示例

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


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

示例1: testAll

function testAll() {
    const imported = all([]);
    const empty = RSVP.Promise.all([]);

    const everyPromise = RSVP.all([
        'string',
        RSVP.resolve(42),
        RSVP.resolve({ hash: 'with values' }),
    ]);

    assertType<RSVP.Promise<[string, number, { hash: string }]>>(everyPromise);

    const anyFailure = RSVP.all([12, 'strings', RSVP.reject('anywhere')]);
    assertType<RSVP.Promise<{}>>(anyFailure);

    let promise1 = RSVP.resolve(1);
    let promise2 = RSVP.resolve('2');
    let promise3 = RSVP.resolve({ key: 13 });
    RSVP.Promise.all([promise1, promise2, promise3], 'my label').then(function(array) {
        assertType<number>(array[0]);
        assertType<string>(array[1]);
        assertType<{ key: number }>(array[2]);
    });
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:24,代碼來源:rsvp-tests.ts

示例2: test

  test('URLTransitionIntent can be applied to an empty state', function(assert) {
    let state = new TransitionState();
    let intent = new URLTransitionIntent(router, '/foo/bar');
    let newState = intent.applyToState(state);
    let handlerInfos = newState.routeInfos;

    assert.equal(handlerInfos.length, 2);
    assert.notOk(
      handlerInfos[0].isResolved,
      'generated state consists of unresolved handler info, 1'
    );
    assert.notOk(
      handlerInfos[1].isResolved,
      'generated state consists of unresolved handler info, 2'
    );
    Promise.all([
      assertHandlerEquals(assert, handlerInfos[0], handlers.foo),
      assertHandlerEquals(assert, handlerInfos[1], handlers.bar),
    ]);
  });
開發者ID:tildeio,項目名稱:router.js,代碼行數:20,代碼來源:transition_intent_test.ts

示例3: Error

let promise2: RSVP.Promise<number, Error> = RSVP.Promise.resolve(2);

let promise3: RSVP.Promise<number, Error> = RSVP.Promise.reject(new Error('3'));
let promise3a: RSVP.Promise<number, Error> = RSVP.reject(new Error('3'));

let promiseArray = [promise1, promise2, promise3];

let promiseHash = {
    promiseA: promise1,
    promiseB: promise2,
    promiseC: promise3,
    notAPromise: 4,
};

RSVP.Promise.all(promiseArray).then(arr => {}, err => {});
RSVP.all(promiseArray).then(arr => {}, err => {});

RSVP.Promise.race(promiseArray).then(arr => {}, err => {});
RSVP.race(promiseArray).then(arr => {}, err => {});

RSVP.allSettled(promiseArray).then(arr => {}, err => {});

let deferred = RSVP.defer();
deferred.resolve('Success');
deferred.promise.then(value => {});

let filterFn = (item: number) => {
    return item > 1;
};
RSVP.filter(promiseArray, filterFn).then(result => {});
開發者ID:DxCx,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:rsvp-tests.ts


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