Created
November 13, 2024 14:27
-
-
Save claudioacioli/b573cb0786f6aac7ca2fd4d50c095b73 to your computer and use it in GitHub Desktop.
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
const schedule = (fileName) => { | |
const worker = new Worker(fileName); | |
return data => new Promise((resolve) => { | |
worker.addEventListener("message", function message (e) { | |
worker.removeEventListener("message", message); | |
return resolve(e.data); | |
}); | |
worker.postMessage(data); | |
}); | |
}; | |
export default schedule; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple way to schedule actions and get promised reactions with js worker.
Usage: