本文整理匯總了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]);
});
}
示例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),
]);
});
示例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 => {});