本文整理匯總了TypeScript中rsvp.Promise.race方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Promise.race方法的具體用法?TypeScript Promise.race怎麽用?TypeScript Promise.race使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsvp.Promise
的用法示例。
在下文中一共展示了Promise.race方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: testRace
function testRace() {
const imported = race([]);
const firstPromise = RSVP.race([{ notAPromise: true }, RSVP.resolve({ some: 'value' })]);
assertType<RSVP.Promise<{ notAPromise: boolean } | { some: string }>>(firstPromise);
let promise1 = RSVP.resolve(1);
let promise2 = RSVP.resolve('2');
RSVP.Promise.race([promise1, promise2], 'my label').then(function(result) {
assertType<string | number>(result);
});
}
示例2: Error
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 => {});
RSVP.hashSettled(promiseHash).then(hash => {
return (