node.js - Async call in node-webworker-threads? -
this hello world example node-webworker-threads page works fine, , generates worker said: hi ali
:
var worker = require('webworker-threads').worker; var worker = new worker(function(){ postmessage("i'm working before postmessage('ali')."); this.onmessage = function(event) { self.postmessage('hi ' + event.data); self.close(); }; }); worker.onmessage = function(event) { console.log("worker said : " + event.data); }; worker.postmessage('ali');
but not work, , can't figure out why. adding settimeout
results in self.postmessage
never getting called:
var worker = require('webworker-threads').worker; var worker = new worker(function(){ postmessage("i'm working before postmessage('ali')."); this.onmessage = function(event) { settimeout(function() { self.postmessage('hi ' + event.data); self.close(); },0); }; }); worker.onmessage = function(event) { console.log("worker said : " + event.data); }; worker.postmessage('ali');
how async calls handled node-webworker-threads?
"workers don't have access settimeout, setinterval, etc. indeed, html timer spec not native v8 , need re-implemented in c++ level."
Comments
Post a Comment