summaryrefslogtreecommitdiff
path: root/js/dispatch.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-08-01 12:36:17 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-08-02 12:49:40 -0400
commit421358e7a9612527fdd9ed9a9a59635c12cdaab5 (patch)
tree0f4d4ca9526745512c7a95a5ea27030a5080e98c /js/dispatch.ts
parentdf8208557d684938e5e50aadbd41b9bcbc37d072 (diff)
Remove dispatch.ts and move assignCmdId to util.ts
Diffstat (limited to 'js/dispatch.ts')
-rw-r--r--js/dispatch.ts29
1 files changed, 0 insertions, 29 deletions
diff --git a/js/dispatch.ts b/js/dispatch.ts
deleted file mode 100644
index eeb00f38e..000000000
--- a/js/dispatch.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-import { typedArrayToArrayBuffer } from "./util";
-import { deno as fbs } from "./msg_generated";
-
-export type MessageCallback = (msg: Uint8Array) => void;
-//type MessageStructCallback = (msg: pb.IMsg) => void;
-
-const channels = new Map<string, MessageCallback[]>();
-
-export function sub(channel: string, cb: MessageCallback): void {
- let subscribers = channels.get(channel);
- if (!subscribers) {
- subscribers = [];
- channels.set(channel, subscribers);
- }
- subscribers.push(cb);
-}
-
-deno.recv((channel: string, ab: ArrayBuffer) => {
- const subscribers = channels.get(channel);
- if (subscribers == null) {
- throw Error(`No subscribers for channel "${channel}".`);
- }
-
- const ui8 = new Uint8Array(ab);
- for (const subscriber of subscribers) {
- subscriber(ui8);
- }
-});