11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst { scheduler } = require('timers/promises'); 61cb0ef41Sopenharmony_ciconst { setTimeout } = require('timers'); 71cb0ef41Sopenharmony_ciconst { 81cb0ef41Sopenharmony_ci strictEqual, 91cb0ef41Sopenharmony_ci rejects, 101cb0ef41Sopenharmony_ci} = require('assert'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciasync function testYield() { 131cb0ef41Sopenharmony_ci await scheduler.yield(); 141cb0ef41Sopenharmony_ci process.emit('foo'); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_citestYield().then(common.mustCall()); 171cb0ef41Sopenharmony_ciqueueMicrotask(common.mustCall(() => { 181cb0ef41Sopenharmony_ci process.addListener('foo', common.mustCall()); 191cb0ef41Sopenharmony_ci})); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciasync function testWait() { 221cb0ef41Sopenharmony_ci let value = 0; 231cb0ef41Sopenharmony_ci setTimeout(() => value++, 10); 241cb0ef41Sopenharmony_ci await scheduler.wait(15); 251cb0ef41Sopenharmony_ci strictEqual(value, 1); 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_citestWait().then(common.mustCall()); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciasync function testCancelableWait1() { 311cb0ef41Sopenharmony_ci const ac = new AbortController(); 321cb0ef41Sopenharmony_ci const wait = scheduler.wait(1e6, { signal: ac.signal }); 331cb0ef41Sopenharmony_ci ac.abort(); 341cb0ef41Sopenharmony_ci await rejects(wait, { 351cb0ef41Sopenharmony_ci code: 'ABORT_ERR', 361cb0ef41Sopenharmony_ci message: 'The operation was aborted', 371cb0ef41Sopenharmony_ci }); 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_citestCancelableWait1().then(common.mustCall()); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciasync function testCancelableWait2() { 431cb0ef41Sopenharmony_ci const wait = scheduler.wait(10000, { signal: AbortSignal.abort() }); 441cb0ef41Sopenharmony_ci await rejects(wait, { 451cb0ef41Sopenharmony_ci code: 'ABORT_ERR', 461cb0ef41Sopenharmony_ci message: 'The operation was aborted', 471cb0ef41Sopenharmony_ci }); 481cb0ef41Sopenharmony_ci} 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_citestCancelableWait2().then(common.mustCall()); 51