Skip to content

Instantly share code, notes, and snippets.

@c7x43t
Created June 16, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7x43t/23660021bc009e716bfe2c21ed3aa08a to your computer and use it in GitHub Desktop.
Save c7x43t/23660021bc009e716bfe2c21ed3aa08a to your computer and use it in GitHub Desktop.
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