-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
sindresorhus
merged 19 commits into
sindresorhus:master
from
ammarbinfaisal1:make-cancelable
Mar 19, 2019
+89
−6
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3b247c5
make cp cancelable (fixes #113)
ammarbinfaisal1 5a74c26
add a test for cancelable spawned processes
ammarbinfaisal1 88beb24
update docs
ammarbinfaisal1 7c743e0
correct usage of p-cancelable
ammarbinfaisal1 71b6abf
provide a default cancelation reason
ammarbinfaisal1 cef4609
fix coding style
ammarbinfaisal1 6c1e31c
add tests fro making spawned process cancelable
ammarbinfaisal1 7786ebd
remove useless ava assertions
ammarbinfaisal1 bef739a
don't use p-cancelable
ammarbinfaisal1 a24a895
remove p-cancelable from package.json
ammarbinfaisal1 629ba5f
make calling cancel method throw its own error
ammarbinfaisal1 9cd06d4
Merge branch 'master' into make-cancelable
ammarbinfaisal 282124c
add more tests
ammarbinfaisal1 2c70e6c
turn cancel true only when process is actually killed
ammarbinfaisal1 3cb85f1
update README
ammarbinfaisal1 089c7b0
update README
ammarbinfaisal1 d85eb02
rename canceled to isCanceled
ammarbinfaisal1 8cd3fcf
update docs
ammarbinfaisal1 f5c35c9
Update index.js
sindresorhus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,14 @@ const execa = require('execa'); | |
//=> 'unicorns' | ||
|
||
// Cancelling a spawned process | ||
const spawned = execa("echo unicorns"); | ||
const spawned = execa("node"); | ||
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 { | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear enough what |
||
|
||
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` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single-quotes
There was a problem hiding this comment.
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 thanspawned
.There was a problem hiding this comment.
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 byspawn()
and globalprocess
have different methods/properties (although some are shared).Node API doc calls it
subprocess
: https://nodejs.org/api/child_process.html#child_process_options_detachedThere was a problem hiding this comment.
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.