doc: recommend events.once to manage 'close' event · nodejs/node@a25d76c · GitHub
Skip to content

Commit a25d76c

Browse files
dfabulichaduh95
authored andcommitted
doc: recommend events.once to manage 'close' event
`events.once` is a great way to manage the `close` / `error` / `exit` events of a child process. It creates a Promise that is fulfilled when the EventEmitter emits the given event or that is rejected if the EventEmitter emits 'error' while waiting. I think a lot of people wrongly think that managing a spawned child process requires writing boilerplate handlers for `close` and `error`, and that there's no `promisify` solution for spawned child processes. In fact, `events.once` is that solution. The docs should explicitly recommend it in examples. PR-URL: #60017 Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 795f32b commit a25d76c

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

doc/api/child_process.md

Lines changed: 10 additions & 6 deletions

0 commit comments

Comments
 (0)