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 denobot committed Feb 1, 2021
1 parent 72b87f5 commit b5e19af
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 b5e19af

Please sign in to comment.