1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00
denoland-deno/std/signal
Bartek Iwańczuk 8e914be742
build: migrate to dlint (#8176)
This commit migrates repository from using "eslint" 
to "dlint" for linting JavaScript code.
2020-11-03 16:19:29 +01:00
..
mod.ts chore: add copyright (#7593) 2020-09-21 08:26:41 -04:00
README.md docs: end sentences with a period in markdown (#7813) 2020-10-04 07:19:11 +11:00
test.ts build: migrate to dlint (#8176) 2020-11-03 16:19:29 +01:00

signal

signal is a module used to capture and monitor OS signals.

usage

The following functions are exposed in mod.ts:

signal

Generates an AsyncIterable which can be awaited on for one or more signals. dispose() can be called when you are finished waiting on the events.

import { signal } from "https://deno.land/std/signal/mod.ts";
const sig = signal(Deno.Signal.SIGUSR1, Deno.Signal.SIGINT);
setTimeout(() => {}, 5000); // Prevents exiting immediately.

for await (const _ of sig) {
  // ..
}

// At some other point in your code when finished listening:
sig.dispose();

onSignal

Registers a callback function to be called on triggering of a signal event.

import { onSignal } from "https://deno.land/std/signal/mod.ts";

const handle = onSignal(Deno.Signal.SIGINT, () => {
  // ...
  handle.dispose(); // de-register from receiving further events.
});