This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* | |
thread() is a function that allows you to execute any isolated function asynchronously in a worker thread. | |
await thread(myFunction, [arg1, arg2, ...]) | |
See more examples and tests below using async functions, transfers, aborts, concurrency,. | |
*/ | |
function thread(func, args, options) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hello world |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(() => console.log("setTimeout #1")) | |
requestAnimationFrame(() => console.log("requestAnimationFrame #1")) | |
scheduler.postTask(() => console.log("scheduler #1")) | |
queueMicrotask(() => console.log("queueMicrotask #1")) | |
Promise.resolve().then(() => console.log("Promise #1")) | |
setTimeout(() => console.log("setTimeout #2")) | |
requestAnimationFrame(() => console.log("requestAnimationFrame #2")) | |
scheduler.postTask(() => console.log("scheduler #2")) | |
queueMicrotask(() => console.log("queueMicrotask #2")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stringify(value) { | |
const map = new Map(); | |
function traverse(value, reference) { | |
if(map.has(value)) | |
return map.get(value); | |
if(Array.isArray(value)) { | |
map.set(value, reference); | |
let result = ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requestAnimationFrame(() => console.log(1)); | |
setTimeout(() => console.log(2), 0); | |
Promise.resolve().then(() => console.log(3)); | |
requestAnimationFrame(() => console.log(4)); | |
setTimeout(() => console.log(5), 0); | |
Promise.resolve().then(() => console.log(6)); | |
// 3, 6, 2, 5, 1, 4 |