NodeJSsubprocess无法发送net.socket fd:3
当编写一个nodejsmultithreading包的时候,主线程可以通过fd:3发送内容,线程可以收到这个消息,但是线程不能通过fd:3发送任何东西
有什么我做错了吗? (line threader.js:45-59是问题显示的地方)
包 (现在只有在github上才能使用)
启动代码:
var Thread = require("threader"); var task = Thread.task(function(){ //Do some calculation }, function(){ //When the calculation response has been sent }); task('a', 2);
我只是想到了这个问题:
thread.js
就像一个套接字服务器, thread.js
就像一个客户端。
服务器必须在连接的上下文中作出响应。
由于您正在使用setTimeout,它本身是一个单独的线程,无法访问连接上下文,因此线程无法侦听数据。
thread.js – 旧的代码
pipe.on('data', function(chunk){ console.log('RECEIVED CONENT THOUGH fd:3 in thread'); console.log(chunk.toString()); }); setTimeout(function () { pipe.write('I piped a thing'); }, 2000);
thread.js – 新的代码
pipe.on('data', function(chunk){ console.log('RECEIVED CONENT THOUGH fd:3 in thread'); console.log(chunk.toString()); }); pipe.write('I piped a thing');
或者 thread.js – 新的代码 – 最好的方法
pipe.on('data', function(chunk){ console.log('RECEIVED CONENT THOUGH fd:3 in thread'); console.log(chunk.toString()); //Real 2 second work but not on a separate thread using setTimeout pipe.write('I piped a thing'); });
我只是重新编写了整个包,从另一个angular度开始,现在它工作…
我认为这个问题是关于挑选线程的。
修补程序将很快推到github。