0

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:

  1. 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.
  2. write 2 lua scripts, let's say they are SA and SB (script for process A, and script for process B).
  3. start 2 processes via jobstart('nvim -l SA ADDRESS') and jobstart('nvim -l SB ADDRESS'). you can see I start two lua scripts and pass them the same pipe address.
  4. 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 via chansend(ID1, data).
  5. 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:

  1. 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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.