Trabajador web en JavaScript
let start = document.querySelector('#start') //it is a button
let stop = document.querySelector('#stop') //it is a button
let show = document.querySelector('#show')
let output
start.addEventListener('click', () => {
//Before creating a web worker, check whether the user's browser supports it:
if (typeof Worker !== 'undefined') {
//check web worker whether undefined or not
if (typeof output === 'undefined') {
output = new Worker('looping.js') //(looping.js) is another file that you can processing anything
}
output.onmessage = (event) => {
show.innerHTML = event.data
}
} else {
alert('Sorry web worker dose not support')
}
})
stop.addEventListener('click', () => {
if (typeof output !== 'undefined') {
output.terminate();
output = undefined
} else {
lert('Sorry web worker dose not support')
}
})
Mohammad Nazim