-
-
Notifications
You must be signed in to change notification settings - Fork 215
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 gracefulCancel
option
#1109
Conversation
f1ea3a5
to
a0cc654
Compare
What happened to the |
I renamed it to Which name do you prefer? I'll update the PR then. |
Have you considered just using |
Yes, that would work too. 👍 Using both signal termination and graceful termination does not seem to make much sense, so they are rather exclusive from each other. Would you prefer this? However, the name should probably highlight that the subprocess will still fail (i.e. Execa promise is rejected), even if its exit is being handled. |
Yes
👍 |
b15a687
to
336efff
Compare
Fixed the PR. 👍 The API is now:
|
} | ||
|
||
throw error; | ||
} | ||
``` | ||
|
||
## Graceful termination | ||
|
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.
Maybe mention that if you write your own scripts just for Unix platforms, a user could also just use SIGTERM
, that this is specifically for cross-platform scripts that should also work on Windows.
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 just added the following line:
This is cross-platform. If you do not need to support Windows, signal handlers can also be used.
It redirects to the following section:
On Unix, most signals (not
SIGKILL
) can be intercepted to perform a graceful exit.process.on('SIGTERM', () => { cleanup(); process.exit(1); })Unfortunately this usually does not work on Windows. The only signal that is somewhat cross-platform is
SIGINT
: on Windows, its handler is triggered when the user typesCTRL-C
in the terminal. Howeversubprocess.kill('SIGINT')
is only handled on Unix.Execa provides the
gracefulCancel
option as a cross-platform alternative to signal handlers.
Retrieves the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) shared by the [`cancelSignal`](#optionscancelsignal) option. | ||
|
||
This requires the [`gracefulCancel`](#optionsgracefulcancel) option to be `true`. | ||
|
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 know you link to the "more info", but would be nice to just mention here that this method should only be called in a subprocess.
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.
Added the following line:
This can only be called inside a subprocess.
I would mention this in the "Features" section in the readme. "Cross-platform graceful termination". |
Fixed 👍 I have added it in the Features section as part of the following bullet point:
|
Great work! I'm very happy with what we ended up with 👍 |
Fixes #1106.
This adds an
abortSignal
option. TheAbortSignal
is shared with the subprocess, which retrieves it usinggetAbortSignal()
. This enables graceful termination, since signals (likeSIGTERM
) handlers do not work on Windows.This also adds
error.isAborted
, which istrue
whenabortSignal
was aborted.