1'use strict'; 2 3const common = require('../common'); 4 5const { scheduler } = require('timers/promises'); 6const { setTimeout } = require('timers'); 7const { 8 strictEqual, 9 rejects, 10} = require('assert'); 11 12async function testYield() { 13 await scheduler.yield(); 14 process.emit('foo'); 15} 16testYield().then(common.mustCall()); 17queueMicrotask(common.mustCall(() => { 18 process.addListener('foo', common.mustCall()); 19})); 20 21async function testWait() { 22 let value = 0; 23 setTimeout(() => value++, 10); 24 await scheduler.wait(15); 25 strictEqual(value, 1); 26} 27 28testWait().then(common.mustCall()); 29 30async function testCancelableWait1() { 31 const ac = new AbortController(); 32 const wait = scheduler.wait(1e6, { signal: ac.signal }); 33 ac.abort(); 34 await rejects(wait, { 35 code: 'ABORT_ERR', 36 message: 'The operation was aborted', 37 }); 38} 39 40testCancelableWait1().then(common.mustCall()); 41 42async function testCancelableWait2() { 43 const wait = scheduler.wait(10000, { signal: AbortSignal.abort() }); 44 await rejects(wait, { 45 code: 'ABORT_ERR', 46 message: 'The operation was aborted', 47 }); 48} 49 50testCancelableWait2().then(common.mustCall()); 51