resolved-sequence-mixed.js (1868B)
1 // |reftest| async 2 // Copyright (C) 2020 Rick Waldron. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-promise.any 7 description: > 8 Resolution ticks are set in a predictable sequence of mixed fulfilled and rejected promises 9 info: | 10 Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability ) 11 12 Let remainingElementsCount be a new Record { [[Value]]: 1 }. 13 ... 14 15 Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. 16 If remainingElementsCount.[[Value]] is 0, then 17 Let error be a newly created AggregateError object. 18 Perform ! DefinePropertyOrThrow(error, "errors", 19 Property Descriptor { 20 [[Configurable]]: true, 21 [[Enumerable]]: false, 22 [[Writable]]: true, 23 [[Value]]: errors 24 }). 25 Return ? Call(promiseCapability.[[Reject]], undefined, « error »). 26 ... 27 flags: [async] 28 includes: [promiseHelper.js] 29 features: [Promise.any] 30 ---*/ 31 32 let sequence = []; 33 34 let p1 = new Promise((_, reject) => { 35 reject(''); 36 }); 37 let p2 = new Promise(resolve => { 38 resolve(''); 39 }); 40 let p3 = new Promise((_, reject) => { 41 reject(''); 42 }); 43 44 sequence.push(1); 45 46 p1.catch(() => { 47 sequence.push(3); 48 assert.sameValue(sequence.length, 3); 49 checkSequence(sequence, 'Expected to be called first.'); 50 }).catch($DONE); 51 52 Promise.any([p1, p2, p3]).then(() => { 53 sequence.push(6); 54 assert.sameValue(sequence.length, 6); 55 checkSequence(sequence, 'Expected to be called fourth.'); 56 }).then($DONE, $DONE); 57 58 p2.then(() => { 59 sequence.push(4); 60 assert.sameValue(sequence.length, 4); 61 checkSequence(sequence, 'Expected to be called second.'); 62 }).catch($DONE); 63 64 sequence.push(2); 65 66 p3.catch(() => { 67 sequence.push(5); 68 assert.sameValue(sequence.length, 5); 69 checkSequence(sequence, 'Expected to be called third.'); 70 }).catch($DONE);