mapfn-async-iterable-sync.js (1028B)
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 An asynchronous mapping function is applied to each item yielded by a 9 synchronous iterable. 10 info: | 11 3.j.ii.6. If _mapping_ is *true*, then 12 a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). 13 ... 14 c. Set _mappedValue_ to Await(_mappedValue_). 15 ... 16 ... 17 8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). 18 flags: [async] 19 includes: [asyncHelpers.js, compareArray.js] 20 features: [Array.fromAsync] 21 ---*/ 22 23 function* syncGen() { 24 for (let i = 0; i < 4; i++) { 25 yield i * 2; 26 } 27 } 28 29 async function asyncMap(val, ix) { 30 return Promise.resolve(val * ix); 31 } 32 33 asyncTest(async () => { 34 const result = await Array.fromAsync({ [Symbol.iterator]: syncGen }, asyncMap); 35 assert.compareArray(result, [0, 2, 8, 18], "async mapfn should be applied to sync iterable"); 36 });