Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a promise-getter to spawned child process objects #29

Closed
callumlocke opened this issue Apr 28, 2016 · 1 comment
Closed

Add a promise-getter to spawned child process objects #29

callumlocke opened this issue Apr 28, 2016 · 1 comment

Comments

@callumlocke
Copy link

promoted from #6 (comment)

Sometimes you want to use execa.spawn() because you need an object representing the child process while it's running, so you can send signals or listen to events. But then you lose the convenience of a promise-based API (i.e. having a thing you can easily await, which will collect up the stdout/stderr for you).

Suggest adding a method to spawned child objects. This method would return a promise that resolves when the child process exits.

const child = execa.spawn(...);

// do any necessary manual stuff with events/signals etc
child.on(...);

// await the final outcome
const { stdio, stderr, code } = await child.exited();

(I'm not sure about the name exited though.)


Possible extra feature: the method could take an optional parameter specifying the expected exit code, e.g. .exited(0). If the child process exits with any other code, the promise rejects. If no exit code is specified, the promise will always resolve when the child process exits, no matter how.

@jamestalmage
Copy link
Contributor

Good News!

We are already on that path (nearly).

See #27 and #18

We will actually be deprecating execa.spawn, you will just use execa.

Those changes will allow for this:

const child = execa(...);

// do any necessary manual stuff with events/signals etc
child.on(...);

// await the final outcome
const { stdio, stderr, code } = await child;

Take a look at those PR's, and if there are additional features or information you would like passed to the promise resolution, comment on the open PR or open a new issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants