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

Make the spawned process cancelable #189

Merged
merged 19 commits into from Mar 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion readme.md
Expand Up @@ -53,8 +53,14 @@ const execa = require('execa');
//=> 'unicorns'

// Cancelling a spawned process
const spawned = execa("echo unicorns");
const spawned = execa("node");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single-quotes

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think process would be a better name than spawned.

Copy link
Collaborator

@ehmicky ehmicky Mar 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this confuse readers about the global variable named process? Child processes returned by spawn() and global process have different methods/properties (although some are shared).

Node API doc calls it subprocess: https://nodejs.org/api/child_process.html#child_process_options_detached

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, subprocess is better.

spawned.cancel();
ehmicky marked this conversation as resolved.
Show resolved Hide resolved
try {
await spawned;
} catch (error) {
console.log(spawned.killed); // true
console.log(error.canceled); // true
}

// Catching an error
try {
Expand Down Expand Up @@ -149,6 +155,13 @@ Execute a command synchronously through the system shell.

Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).

### spawned.cancel()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear enough what spawned is. And it's weird to place the docs here. I think it would be better to document it in the execa() section.


Cancel a process spawned using execa. Calling this method kills it.

Throws an error with `error.canceled` equal to `true`, provided that the process gets canceled.
Process would not get canceled if it has already exited or has been killed by `spawned.kill()`.
ehmicky marked this conversation as resolved.
Show resolved Hide resolved

### options

Type: `Object`
Expand Down