假设风箱是我的app.js
var app = express();
let server = require("http").Server(app);
let io = require("socket.io").listen(server);
require("./forked-background-process")(io);
然后是forked-background-process
,它创建了一个分叉的过程
let schedule = require("node-schedule");
module.exports = io => {
schedule.scheduleJob("40 9 11 * * *", async function() {
const jobAlertForkedProcess = fork('./startup/schedule-jobs');
await jobAlertForkedProcess.send(2, io);
jobAlertForkedProcess.on('message', (sum) => {
jobAlertForkedProcess.kill();
});
});
}
这是我分叉的流程内容startup/schedule-jobs
:
process.on('message', async (type, io) => {
});
但这会导致以下错误This handle type cannot be sent at ChildProcess.target._send