Created
March 25, 2014 10:28
-
-
Save latentflip/9758815 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 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