Skip to content

Instantly share code, notes, and snippets.

@wilk
Created September 8, 2018 09:47
Show Gist options
  • Save wilk/5a15d014894c2dae7d4d78406c1927cb to your computer and use it in GitHub Desktop.
Save wilk/5a15d014894c2dae7d4d78406c1927cb to your computer and use it in GitHub Desktop.
microjob example
(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