1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -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"
| "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 =
| {
success: true;

View file

@ -741,40 +741,6 @@ declare namespace Deno {
*/
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 = {
cbreak: boolean;
};

View file

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

View file

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