diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-08-09 12:17:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-09 12:17:08 -0700 |
commit | fb87cb38eca7a2d490c3e70738407dc6538e80d3 (patch) | |
tree | 29e81258ca714594f0b6b325ddd41bb5f8c54257 /js/main.ts | |
parent | 0e96125260f2d78718e57cac95c7dc672bb24e57 (diff) |
First pass at setTimeout with Tokio (#434)
Diffstat (limited to 'js/main.ts')
-rw-r--r-- | js/main.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/js/main.ts b/js/main.ts index 1585fd092..87fe30e6c 100644 --- a/js/main.ts +++ b/js/main.ts @@ -4,6 +4,7 @@ import { deno as fbs } from "gen/msg_generated"; import { assert, log, assignCmdId } from "./util"; import * as runtime from "./runtime"; import { libdeno } from "./globals"; +import * as timers from "./timers"; function startMsg(cmdId: number): Uint8Array { const builder = new flatbuffers.Builder(); @@ -17,8 +18,26 @@ function startMsg(cmdId: number): Uint8Array { return builder.asUint8Array(); } +function onMessage(ui8: Uint8Array) { + const bb = new flatbuffers.ByteBuffer(ui8); + const base = fbs.Base.getRootAsBase(bb); + switch (base.msgType()) { + case fbs.Any.TimerReady: { + const msg = new fbs.TimerReady(); + assert(base.msg(msg) != null); + timers.onMessage(msg); + break; + } + default: { + assert(false, "Unhandled message type"); + break; + } + } +} + /* tslint:disable-next-line:no-default-export */ export default function denoMain() { + libdeno.recv(onMessage); runtime.setup(); // First we send an empty "Start" message to let the privlaged side know we |