From 421358e7a9612527fdd9ed9a9a59635c12cdaab5 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 1 Aug 2018 12:36:17 -0400 Subject: Remove dispatch.ts and move assignCmdId to util.ts --- js/dispatch.ts | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 js/dispatch.ts (limited to 'js/dispatch.ts') 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(); - -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); - } -}); -- cgit v1.2.3