2020-09-25 19:15:18 -04:00
|
|
|
# signal
|
|
|
|
|
2020-10-03 16:19:11 -04:00
|
|
|
signal is a module used to capture and monitor OS signals.
|
2020-09-25 19:15:18 -04:00
|
|
|
|
|
|
|
# usage
|
|
|
|
|
2020-10-03 16:19:11 -04:00
|
|
|
The following functions are exposed in `mod.ts`:
|
2020-09-25 19:15:18 -04:00
|
|
|
|
|
|
|
## 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
|
2020-09-26 10:14:56 -04:00
|
|
|
import { signal } from "https://deno.land/std/signal/mod.ts";
|
2020-09-25 19:15:18 -04:00
|
|
|
const sig = signal(Deno.Signal.SIGUSR1, Deno.Signal.SIGINT);
|
2020-10-03 16:19:11 -04:00
|
|
|
setTimeout(() => {}, 5000); // Prevents exiting immediately.
|
2020-09-25 19:15:18 -04:00
|
|
|
|
|
|
|
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
|
2020-09-26 10:14:56 -04:00
|
|
|
import { onSignal } from "https://deno.land/std/signal/mod.ts";
|
2020-09-25 19:15:18 -04:00
|
|
|
|
|
|
|
const handle = onSignal(Deno.Signal.SIGINT, () => {
|
|
|
|
// ...
|
2020-10-03 16:19:11 -04:00
|
|
|
handle.dispose(); // de-register from receiving further events.
|
2020-09-25 19:15:18 -04:00
|
|
|
});
|
|
|
|
```
|