Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2923265
test_async_await_microtask.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_async_await_microtask.cjs
View Options
var jobQueue = [];
function setTimeout(cb, time, cbarg) {
var speedup = 10;
var runTime = Date.now() + time / speedup;
if (!jobQueue[runTime]) {
jobQueue[runTime] = [];
}
jobQueue[runTime].push(function () {
cb(cbarg);
});
}
function flushQueue() {
var curTime = Date.now();
var empty = true;
for (var runTime in jobQueue) {
empty = false;
if (curTime >= runTime) {
var jobs = jobQueue[runTime];
delete jobQueue[runTime];
jobs.forEach(function (job) {
job();
});
}
}
if (!empty) {
Promise.resolve().then(flushQueue);
}
}
function asyncTestPassed() {
console.log('test_async_await_microtask.cjs: OK');
}
function testCode() {
(async function () {
await Promise.resolve();
console.log('after');
var a1 = await new Promise(function (resolve) {
setTimeout(resolve, 800, 'foo');
});
var a2 = await new Promise(function (resolve) {
setTimeout(resolve, 800, 'bar');
});
if (a1 + a2 === 'foobar') {
asyncTestPassed();
} else {
console.log('test_async_await_microtask.cjs: FAIL');
}
})();
}
try {
testCode();
Promise.resolve().then(flushQueue);
} catch (e) {
console.log('test_async_await_microtask.cjs: exception: ' + e);
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Mar 27, 4:25 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512347
Default Alt Text
test_async_await_microtask.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment