I tried something like this in the forked child process:
WriterPlugin.js (child process)
function sendCursor(){
try {
let cursor = await getQueryCursor(reqBody, db);
cursor.on('data', (data) => {
process.send(data);
})
} catch (error) {
process.send({
message: error.toString(),
status: 400
})
}
}
controller.js (parent process)
const childProcess = fork(fileToExec);
childProcess.send(objectToProcess);
childProcess.on('message', (data) => {
reply.send(data);
})
This one printed just last data of cursor and i faced with a fastifyError:
"code":"FST_ERR_REP_ALREADY_SENT","statusCode":500},"msg":"Reply already sent"}
How can i properly handle the cursor.stream() from a forked child process using fastify?