1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 16:42:21 -05:00

feat(runtime): stabilize addSignalListener API (#13438)

This commit is contained in:
Yoshiya Hinosawa 2022-01-31 14:16:39 +09:00 committed by GitHub
parent efa02ffa2a
commit 245f69256b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 40 deletions

View file

@ -2298,6 +2298,36 @@ declare namespace Deno {
| "SIGXCPU" | "SIGXCPU"
| "SIGXFSZ"; | "SIGXFSZ";
/** Registers the given function as a listener of the given signal event.
*
* ```ts
* Deno.addSignalListener("SIGTERM", () => {
* console.log("SIGTERM!")
* });
* ```
*
* NOTE: This functionality is not yet implemented on Windows.
*/
export function addSignalListener(signal: Signal, handler: () => void): void;
/** Removes the given signal listener that has been registered with
* Deno.addSignalListener.
*
* ```ts
* const listener = () => {
* console.log("SIGTERM!")
* };
* Deno.addSignalListener("SIGTERM", listener);
* Deno.removeSignalListener("SIGTERM", listener);
* ```
*
* NOTE: This functionality is not yet implemented on Windows.
*/
export function removeSignalListener(
signal: Signal,
handler: () => void,
): void;
export type ProcessStatus = export type ProcessStatus =
| { | {
success: true; success: true;

View file

@ -741,40 +741,6 @@ declare namespace Deno {
*/ */
export function applySourceMap(location: Location): Location; export function applySourceMap(location: Location): Location;
/** **UNSTABLE**: new API, yet to be vetted.
*
* Registers the given function as a listener of the given signal event.
*
* ```ts
* Deno.addSignalListener("SIGTERM", () => {
* console.log("SIGTERM!")
* });
* ```
*
* NOTE: This functionality is not yet implemented on Windows.
*/
export function addSignalListener(signal: Signal, handler: () => void): void;
/** **UNSTABLE**: new API, yet to be vetted.
*
* Removes the given signal listener that has been registered with
* Deno.addSignalListener.
*
* ```ts
* const listener = () => {
* console.log("SIGTERM!")
* };
* Deno.addSignalListener("SIGTERM", listener);
* Deno.removeSignalListener("SIGTERM", listener);
* ```
*
* NOTE: This functionality is not yet implemented on Windows.
*/
export function removeSignalListener(
signal: Signal,
handler: () => void,
): void;
export type SetRawOptions = { export type SetRawOptions = {
cbreak: boolean; cbreak: boolean;
}; };

View file

@ -108,11 +108,11 @@
resolveDns: __bootstrap.net.resolveDns, resolveDns: __bootstrap.net.resolveDns,
upgradeWebSocket: __bootstrap.http.upgradeWebSocket, upgradeWebSocket: __bootstrap.http.upgradeWebSocket,
kill: __bootstrap.process.kill, kill: __bootstrap.process.kill,
addSignalListener: __bootstrap.signals.addSignalListener,
removeSignalListener: __bootstrap.signals.removeSignalListener,
}; };
__bootstrap.denoNsUnstable = { __bootstrap.denoNsUnstable = {
addSignalListener: __bootstrap.signals.addSignalListener,
removeSignalListener: __bootstrap.signals.removeSignalListener,
emit: __bootstrap.compilerApi.emit, emit: __bootstrap.compilerApi.emit,
setRaw: __bootstrap.tty.setRaw, setRaw: __bootstrap.tty.setRaw,
consoleSize: __bootstrap.tty.consoleSize, consoleSize: __bootstrap.tty.consoleSize,

View file

@ -179,7 +179,6 @@ fn op_signal_bind(
sig: String, sig: String,
_: (), _: (),
) -> Result<ResourceId, AnyError> { ) -> Result<ResourceId, AnyError> {
super::check_unstable(state, "Deno.signal");
let signo = signal_str_to_int(&sig)?; let signo = signal_str_to_int(&sig)?;
if signal_hook_registry::FORBIDDEN.contains(&signo) { if signal_hook_registry::FORBIDDEN.contains(&signo) {
return Err(type_error(format!( return Err(type_error(format!(
@ -201,8 +200,6 @@ async fn op_signal_poll(
rid: ResourceId, rid: ResourceId,
_: (), _: (),
) -> Result<bool, AnyError> { ) -> Result<bool, AnyError> {
super::check_unstable2(&state, "Deno.signal");
let resource = state let resource = state
.borrow_mut() .borrow_mut()
.resource_table .resource_table
@ -222,7 +219,6 @@ pub fn op_signal_unbind(
rid: ResourceId, rid: ResourceId,
_: (), _: (),
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
super::check_unstable(state, "Deno.signal");
state.resource_table.close(rid)?; state.resource_table.close(rid)?;
Ok(()) Ok(())
} }