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:
parent
efa02ffa2a
commit
245f69256b
4 changed files with 32 additions and 40 deletions
30
cli/dts/lib.deno.ns.d.ts
vendored
30
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -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;
|
||||
|
|
34
cli/dts/lib.deno.unstable.d.ts
vendored
34
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue