tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

async-await-interleaved.js (1001B)


      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 <mslekova@chromium.org>
      7 esid: await
      8 description: >
      9  Await on async functions and builtin Promises are properly interleaved,
     10  meaning await takes only 1 tick on the microtask queue.
     11 flags: [async]
     12 features: [async-functions]
     13 includes: [compareArray.js]
     14 ---*/
     15 
     16 const actual = [];
     17 const expected = [
     18  'Await: 1',
     19  'Promise: 1',
     20  'Await: 2',
     21  'Promise: 2'
     22 ];
     23 
     24 async function pushAwait(value) {
     25  actual.push('Await: ' + value);
     26 }
     27 
     28 async function callAsync() {
     29  await pushAwait(1);
     30  await pushAwait(2);
     31 }
     32 
     33 function checkAssertions() {
     34  assert.compareArray(actual, expected,
     35    'Async/await and promises should be interleaved');
     36 }
     37 
     38 callAsync();
     39 
     40 new Promise(function (resolve) {
     41  actual.push('Promise: 1');
     42  resolve();
     43 }).then(function () {
     44  actual.push('Promise: 2');
     45 }).then(checkAssertions).then($DONE, $DONE);