Skip to content

Commit

Permalink
Add signal handlers (denoland/deno#3757)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored and caspervonb committed Jan 31, 2021
1 parent a6d1807 commit 718fd73
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,39 @@ Uncaught NotFound: No such file or directory (os error 2)
at handleAsyncMsgFromRust (deno/js/dispatch.ts:27:17)
```

### Handle OS Signals

[API Reference](https://deno.land/typedoc/index.html#signal)

You can use `Deno.signal()` function for handling OS signals.

```
for await (const _ of Deno.signal(Deno.Signal.SIGINT)) {
console.log("interrupted!");
}
```
`Deno.signal()` also works as a promise.
```
await Deno.signal(Deno.Singal.SIGINT);
console.log("interrupted!");
```
If you want to stop watching the signal, you can use `dispose()` method of the
signal object.
```
const sig = Deno.signal(Deno.Signal.SIGINT);
setTimeout(() => { sig.dispose(); }, 5000);

for await (const _ of sig) {
console.log("interrupted");
}
```
The above for-await loop exits after 5 seconds when sig.dispose() is called.
### Linking to third party code
In the above examples, we saw that Deno could execute scripts from URLs. Like
Expand Down

0 comments on commit 718fd73

Please sign in to comment.