'Is there a synchronous version of child_process.fork() in node.js?
There is spawn
and spawnSync
, but there is no forkSync
for fork
. Or did I fail to find it? If not, why is there no forkSync
?
Solution 1:[1]
fork
is only synchronous, returning ChildProcess
. There is no callback involved, nor a promise to be fulfilled.
(i.e. There is no child_process.forkSync
for the same reason there is no console.logSync
)
EDIT: In comparison to spawn
and spawnSync
- the purpose of spawnSync
is to wait till the child process is done, not just to launch it. The sole difference between fork
and spawn
is the existence of a communication channel between the parent and the child process, which is useless if the parent is frozen in time. Thus, forkSync
in that context would make no sense (as different than spawnSync
).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |