【发布时间】:2017-01-21 23:42:24
【问题描述】:
在编写 nodejs 多线程包时,主线程可以通过 fd:3 发送内容并且线程可以接收消息,但随后线程无法通过 fd:3 发送回任何内容
我做错了什么吗? (threader.js:45-59 行是问题所在)
Package(目前仅在 github 上,我的包正在运行)
启动代码:
var Thread = require("threader");
var task = Thread.task(function(){
//Do some calculation
}, function(){
//When the calculation response has been sent
});
task('a', 2);
【问题讨论】:
-
发送过程中有什么例子吗
-
当一个线程启动时,如果正确注销“Loggin working”,那么它会添加一个新的 net.Socket({fd:3}).on('data') 并且当它获取任何数据时它应该只需注销“虽然 fd:3 in thread”,但在线程启动 10 毫秒后,它应该通过 net.socket 发送“I piped a thing”,然后在主线程中它应该说“Receive fd: 3 in主线程”,但这永远不会发生
-
有趣的是,这段代码只会注销“从线程 0 发送”,而不是其他任何东西,它只是坐在那里运行,fd:3 可以自动关闭吗? > github.com/Hobgoblin101/Threader/blob/master/test2.js
标签: node.js multithreading sockets