使用SetImmediate()
方法时发生错误。
这是错误代码。
Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
at process.target.send (internal/child_process.js:599:16)
at Immediate.mine (/Volumes/Work/ProjectsByClient/ULC/Exerices/ex6/coinGenerator.js:30:13)
at <anonymous>
Emitted 'error' event at:
at process.nextTick (internal/child_process.js:603:35)
at process._tickCallback (internal/process/next_tick.js:112:11)
这是我的原始剧本
mine()
async function mine () {
const newBlocks = await Bitcoin.mine(miner.pk, miner.sk)
// console.log(newBlocks)
if (newBlocks !== null && newBlocks.length > 0) {
console.log(newBlocks)
process.send({
type: 'info',
newBlocks: newBlocks
})
}
setImmediate(mine)
}
当我不使用异步功能,但必须使用异步功能时,此方法有效。