作者:phpxiaohui | 来源:互联网 | 2023-07-20 21:25
Icurrentlyhaveanoperationinamodulethatisblocking,soImlookingatmakingthisintoachi
I currently have an operation in a module that is blocking, so I'm looking at making this into a child process that I fork instead.
我目前在一个阻塞的模块中有一个操作,所以我正在考虑把它变成一个我代替的子进程。
If I want to do that, then I of course need to modify the architecture of my module. The module requires that a dependency is injected by calling the module as a function, passing in the dependency, like so:
如果我想这样做,那么我当然需要修改我的模块的架构。该模块要求通过将模块作为函数调用来注入依赖项,并传入依赖项,如下所示:
var dependency = { name: "Bob" }
require('worker')(dependency)
Then in my worker
module:
然后在我的工人模块中:
module.exports = function (dependency) {
// Outputs { name: "Bob" }
console.log(dependency)
}
How can I turn this example into a child process being forked?
如何将此示例转换为分叉的子进程?
3 个解决方案