async-iterable-async-mapped-awaits-once.js (778B)
1 // |reftest| async 2 // Copyright (C) 2023 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-array.fromasync 7 description: > 8 Async-iterable awaits each input once with mapping callback 9 includes: [asyncHelpers.js] 10 flags: [async] 11 features: [Array.fromAsync] 12 ---*/ 13 14 asyncTest(async function () { 15 async function* generateInput () { 16 yield* [ 0, 1, 2 ]; 17 } 18 const input = generateInput(); 19 let awaitCounter = 0; 20 await Array.fromAsync(input, v => { 21 return { 22 // This “then” method should occur three times: 23 // one for each value from the input. 24 then (resolve, reject) { 25 awaitCounter ++; 26 resolve(v); 27 }, 28 }; 29 }); 30 assert.sameValue(awaitCounter, 3); 31 });