Created
September 8, 2018 09:47
-
-
Save wilk/5a15d014894c2dae7d4d78406c1927cb to your computer and use it in GitHub Desktop.
microjob example
This file contains 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
(async () => { | |
const { job } = require('microjob') | |
try { | |
// this function will be executed in another thread | |
const res = await job(() => { | |
let i = 0 | |
for (i = 0; i < 1000000; i++) { | |
// heavy CPU load ... | |
} | |
return i | |
}) | |
console.log(res) // 1000000 | |
} catch (err) { | |
console.error(err) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment