I want to write a plugin that start 2 child processes. let's say the main nvim process is P, parent. and two child processes are A and B.
In process A, I will do some calculation and write data to process B. The calculation is heavy so I want to use another process so make it async and performant.
Now I am going to follow these steps:
- in P process, create a pipe via
serverstart
, then I got the pipe address from function returned value. let's say the address is ADDRESS. - write 2 lua scripts, let's say they are SA and SB (script for process A, and script for process B).
- start 2 processes via
jobstart('nvim -l SA ADDRESS')
andjobstart('nvim -l SB ADDRESS')
. you can see I start two lua scripts and pass them the same pipe address. - in SA, it will connect the pipe channel via
sockconnect('pipe', ADDRESS)
, get the channel id, let's say it's ID1. do the calculation, send data viachansend(ID1, data)
. - in sb, it will also connect the pipe channel via
sockconnect('pipe', ADDRESS, {on_data=callback})
, so once there is any data received, it read and consumes them.
But I have some questions:
- is pipe channel only available for parent-child process data transfer? or it can be used between two child processes from the same parent?
please also give any comments.