Debian Codegraph @

js/src/tests/test262/language/expressions/await/async-generator-interleaved.js

raw
1 // |reftest| async
2 // Copyright 2018 the V8 project authors. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 author: Maya Lekova <[email protected]>
7 esid: await
8 description: >
9 Await on async generator functions and builtin Promises are properly
10 interleaved, meaning await takes only 1 tick on the microtask queue.
11 flags: [async]
12 features: [async-functions, async-iteration]
13 includes: [compareArray.js]
14 ---*/
15
16 const actual = [];
17 const expected = [ 'await', 1, 'await', 2 ];
18 const iterations = 2;
19
20 async function pushAwait() {
21 actual.push('await');
22 }
23
24 async function* callAsync() {
25 for (let i = 0; i < iterations; i++) {
26 await pushAwait();
27 }
28 return 0;
29 }
30
31 function checkAssertions() {
32 assert.compareArray(actual, expected,
33 'Async/await and promises should be interleaved');
34 }
35
36 callAsync().next();
37
38 new Promise(function (resolve) {
39 actual.push(1);
40 resolve();
41 }).then(function () {
42 actual.push(2);
43 }).then(checkAssertions).then($DONE, $DONE);