tor-browser

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

yield-priority-timers.any.js (993B)


      1 'use strict';
      2 
      3 // Queues a zero ms timer that yields 3 times using `yieldParams`, then posts 2
      4 // more 0 ms timers.
      5 //
      6 // Returns {tasks, ids} where `tasks` is an array of promises associated with
      7 // the timers and `ids` is an array of task ids appended to by the scheduled
      8 // tasks.
      9 function postTestTasks() {
     10  const tasks = [];
     11  const ids = [];
     12 
     13  tasks.push(new Promise(resolve => {
     14    setTimeout(async () => {
     15      ids.push('t1');
     16      for (let i = 1; i < 4; i++) {
     17        await scheduler.yield();
     18        ids.push('y' + i);
     19      }
     20      resolve();
     21    });
     22  }));
     23 
     24  tasks.push(new Promise(resolve => {
     25    setTimeout(() => { ids.push('t2'); resolve(); });
     26  }));
     27  tasks.push(new Promise(resolve => {
     28    setTimeout(() => { ids.push('t3'); resolve(); });
     29  }));
     30  return {tasks, ids};
     31 }
     32 
     33 promise_test(async t => {
     34  const {tasks, ids} = postTestTasks();
     35  await Promise.all(tasks);
     36  assert_equals(ids.join(), 't1,y1,y2,y3,t2,t3');
     37 }, 'yield() with timer tasks (inherit signal)');