summaryrefslogtreecommitdiff
path: root/std/signal/README.md
blob: 7a152cdca7be0190b5a2c3d46508602aa1bf8590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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.

```typescript
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.

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

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