summaryrefslogtreecommitdiff
path: root/std/manual.md
diff options
context:
space:
mode:
Diffstat (limited to 'std/manual.md')
-rw-r--r--std/manual.md33
1 files changed, 33 insertions, 0 deletions
diff --git a/std/manual.md b/std/manual.md
index ece5a755b..204701566 100644
--- a/std/manual.md
+++ b/std/manual.md
@@ -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