Created
June 16, 2021 15:40
-
-
Save c7x43t/23660021bc009e716bfe2c21ed3aa08a to your computer and use it in GitHub Desktop.
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
var i=0; | |
setInterval(()=>console.log(i),1000); | |
var a=[]; | |
setInterval(function abc(){i++;a.push([Date.now()])},0); | |
// replace next line with worker | |
//setInterval(function abc(){i++;a[a.length-1].push(Date.now())},0); | |
///// | |
function abcdef() { | |
myWorker.postMessage([1, 2]); | |
console.log('Message posted to worker'); | |
} | |
var workerFunc=` | |
onmessage = function(e) { | |
//console.log('Message received from main script'); | |
//var workerResult = 'Result: ' + (e.data[0] * e.data[1]); | |
//console.log('Posting message back to main script'); | |
setInterval(()=>postMessage(null),0); | |
} | |
`; | |
var blob = new Blob([workerFunc], {type : 'application/javascript'}); | |
var blobUrl=URL.createObjectURL(blob); | |
var k=[]; | |
for(var i=0;i<10;i++){ | |
k.push(0); | |
;(function(i){ | |
var myWorker = new Worker(blobUrl); | |
myWorker.onmessage=function(){ | |
a[k[i]++].push(Date.now()); | |
}; | |
}(i)); | |
} | |
abcdef(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment