-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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 signal handlers #3757
Add signal handlers #3757
Conversation
0d04f68
to
79f5762
Compare
@kt3k Is this working now? It looks like it. |
@ry Yes, this is ready for review now. PTAL. |
cli/js/signal_test.ts
Outdated
} | ||
|
||
if (Deno.build.os === "win") { | ||
testPerm({ run: true }, async function signalsNotImplemented(): Promise< |
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.
Why is run
permission needed here?
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.
Sorry. A mistake. Will remove.
cli/js/signals.ts
Outdated
if (done) { | ||
throw new DenoError(ErrorKind.NotFound, STREAM_DISPOSED_MESSAGE); | ||
} |
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.
Seems superfluous... just return done
?
cli/ops/signal.rs
Outdated
#[cfg(unix)] | ||
#[derive(Deserialize)] | ||
struct UnbindSignalArgs { | ||
rid: i32, | ||
} | ||
|
||
#[cfg(unix)] | ||
#[derive(Deserialize)] | ||
struct PollSignalArgs { | ||
rid: i32, | ||
} |
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.
How about single SignalArgs
?
cli/js/signals.ts
Outdated
dispose(): void { | ||
this.disposed = true; | ||
sendSync(dispatch.OP_UNBIND_SIGNAL, { rid: this.rid }); | ||
} |
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 guard against additional calls to dispose()
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.
Sounds a good idea.
cli/js/dispatch.ts
Outdated
@@ -74,6 +74,9 @@ export let OP_HOSTNAME: number; | |||
export let OP_OPEN_PLUGIN: number; | |||
export let OP_COMPILE: number; | |||
export let OP_TRANSPILE: number; | |||
export let OP_BIND_SIGNAL: number; | |||
export let OP_UNBIND_SIGNAL: number; | |||
export let OP_POLL_SIGNAL: number; |
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 be better to call these
OP_SIGNAL_BIND
OP_SIGNAL_UNBIND
OP_SIGNAL_POLL
d52d37f
to
87112aa
Compare
Is now able to listen to multiple signals at once? If it can, it must be excellent |
@axetroy Sorry. I haven't included that feature in this PR because this one is already a little big (to me) and I'm not so sure about the interface of that feature ( |
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.
LGTM - very nice patch in the end ! Thank you for seeing this through @kt3k.
This PR adds signal handler APIs.
Deno.signal(signo)
function returns an async iterator of the given signal number. The returned object also works as a promise which is resolved when the first signal is received.Streaming API
Promise API
The stream can be disposed by calling
.dispose()
method.The above for-await-of loop exits after 5000ms.
Note: Signal handlers doesn't block the program exiting. The following program exits immediately.
Signal handlers must be used with some other main things, such as servers, etc, and those main routines should block the program from exiting. See the discussions in #3721 #3715 for details.
This PR also adds the following shorthand functions:
These shorthand names are inspired by methods of
tokio::signal::unix::SignalKind
.Internals
This PR adds 3 ops:
And 1 resource:
closes #2339
ref #3610 (an older version of this PR)