diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-22 14:23:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 14:23:42 +0200 |
commit | 86354a29a40fb97e334f951428239ab8e171e2dd (patch) | |
tree | 2f0d8cc2680aa4ccbaf865b427976b3f810b6920 /timers.ts | |
parent | ef9dc2464e10510bdcc4be9eae431e3dcf7f7999 (diff) |
Delete go implementation (#276)
The go prototype will remain at https://github.com/ry/deno/tree/golang
Diffstat (limited to 'timers.ts')
-rw-r--r-- | timers.ts | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/timers.ts b/timers.ts deleted file mode 100644 index da2cccd89..000000000 --- a/timers.ts +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2018 Ryan Dahl <ry@tinyclouds.org> -// All rights reserved. MIT License. -import { deno as pb } from "./msg.pb"; -import { pubInternal, sub } from "./dispatch"; -import { assert } from "./util"; - -let nextTimerId = 1; - -// tslint:disable-next-line:no-any -export type TimerCallback = (...args: any[]) => void; - -interface Timer { - id: number; - cb: TimerCallback; - interval: boolean; - // tslint:disable-next-line:no-any - args: any[]; - delay: number; // milliseconds -} - -const timers = new Map<number, Timer>(); - -export function initTimers() { - sub("timers", onMessage); -} - -function onMessage(payload: Uint8Array) { - const msg = pb.Msg.decode(payload); - assert(msg.command === pb.Msg.Command.TIMER_READY); - const { timerReadyId, timerReadyDone } = msg; - const timer = timers.get(timerReadyId); - if (!timer) { - return; - } - timer.cb(...timer.args); - if (timerReadyDone) { - timers.delete(timerReadyId); - } -} - -function setTimer( - cb: TimerCallback, - delay: number, - interval: boolean, - // tslint:disable-next-line:no-any - args: any[] -): number { - const timer = { - id: nextTimerId++, - interval, - delay, - args, - cb - }; - timers.set(timer.id, timer); - pubInternal("timers", { - command: pb.Msg.Command.TIMER_START, - timerStartId: timer.id, - timerStartInterval: timer.interval, - timerStartDelay: timer.delay - }); - return timer.id; -} - -export function setTimeout( - cb: TimerCallback, - delay: number, - // tslint:disable-next-line:no-any - ...args: any[] -): number { - return setTimer(cb, delay, false, args); -} - -export function setInterval( - cb: TimerCallback, - delay: number, - // tslint:disable-next-line:no-any - ...args: any[] -): number { - return setTimer(cb, delay, true, args); -} - -export function clearTimer(id: number) { - timers.delete(id); - pubInternal("timers", { - command: pb.Msg.Command.TIMER_CLEAR, - timerClearId: id - }); -} |