mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-28 00:22:05 +00:00
18 lines
491 B
JavaScript
18 lines
491 B
JavaScript
// // block for `time` ms, then return the number of loops we could run in that time:
|
|
function expensive(time) {
|
|
let start = Date.now(),
|
|
count = 0
|
|
while (Date.now() - start < time) count++
|
|
return count
|
|
}
|
|
|
|
// Respond to message from parent thread
|
|
self.addEventListener('message', (event) => {
|
|
console.log('worker', event.data)
|
|
|
|
if (event.data.action === 'expensive' && event.data.time) {
|
|
// Post data to parent thread
|
|
self.postMessage(expensive(Number(event.data.time)))
|
|
}
|
|
})
|