mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 17:37:14 +00:00
1b46a95b06
* added missing eslint-loader that prevented the example to run and changed freeWorker to terminate a worker and create a new since we can not really free a worker * proper remove long running worker from longRunningWorkers array when done * polish web-worker example set nuxt to 'latest' version this will change this will also change
20 lines
543 B
JavaScript
20 lines
543 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)))
|
|
} else {
|
|
self.postMessage({ hello: 'from worker' })
|
|
}
|
|
})
|