Skip to content

Instantly share code, notes, and snippets.

@latentflip
Created March 25, 2014 10:28
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 latentflip/9758815 to your computer and use it in GitHub Desktop.
Save latentflip/9758815 to your computer and use it in GitHub Desktop.
var weevil = require('weevil');
var deval = require('deval');
console.log('Lets do something that should be blocking:');
//this code will be run in a webworker
var worker = weevil(deval(function () {
var start = +new Date();
for (var i=0; i<10000000000000; i++) {
//blockety block
}
var end = +new Date();
weevil.send('DONE!', end - start);
}));
var interval = setInterval(function () {
console.log('Look, I aint blocked!');
}, 50);
worker.on('DONE!', function (time) {
console.log('Count was done in', time + 'ms');a
clearInterval(interval);
});
//Outputs:
// Lets do something that should be blocking:
// Look, I aint blocked!
// Look, I aint blocked!
// ...
// Look, I aint blocked!
// Count was done in 2061ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment