summaryrefslogtreecommitdiff
path: root/std/signal/mod.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/signal/mod.ts')
-rw-r--r--std/signal/mod.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/std/signal/mod.ts b/std/signal/mod.ts
new file mode 100644
index 000000000..e368edbd1
--- /dev/null
+++ b/std/signal/mod.ts
@@ -0,0 +1,28 @@
+import { MuxAsyncIterator } from "../util/async.ts";
+
+export function signal(
+ ...signos: [number, ...number[]]
+): AsyncIterable<void> & { dispose: () => void } {
+ const mux = new MuxAsyncIterator<void>();
+
+ if (signos.length < 1) {
+ throw new Error(
+ "No signals are given. You need to specify at least one signal to create a signal stream."
+ );
+ }
+
+ const streams = signos.map(Deno.signal);
+
+ streams.forEach(stream => {
+ mux.add(stream);
+ });
+
+ // Create dispose method for the muxer of signal streams.
+ const dispose = (): void => {
+ streams.forEach(stream => {
+ stream.dispose();
+ });
+ };
+
+ return Object.assign(mux, { dispose });
+}