diff --git a/dispatch.ts b/dispatch.ts index 01bd58bedd..1ed6af71ec 100644 --- a/dispatch.ts +++ b/dispatch.ts @@ -41,8 +41,7 @@ export function pub(channel: string, payload: Uint8Array): null | ArrayBuffer { // Internal version of "pub". // TODO add internal version of "sub" -// TODO rename to pubInternal() -export function sendMsg(channel: string, obj: pb.IMsg): null | pb.Msg { +export function pubInternal(channel: string, obj: pb.IMsg): null | pb.Msg { const msg = pb.Msg.fromObject(obj); const ui8 = pb.Msg.encode(msg).finish(); const resBuf = pub(channel, ui8); diff --git a/fetch.ts b/fetch.ts index e0ac4db714..42acfa22f0 100644 --- a/fetch.ts +++ b/fetch.ts @@ -2,11 +2,11 @@ // All rights reserved. MIT License. import { assert, log, createResolvable, Resolvable } from "./util"; import * as util from "./util"; -import * as dispatch from "./dispatch"; +import { pubInternal, sub } from "./dispatch"; import { main as pb } from "./msg.pb"; export function initFetch() { - dispatch.sub("fetch", (payload: Uint8Array) => { + sub("fetch", (payload: Uint8Array) => { const msg = pb.Msg.decode(payload); assert(msg.command === pb.Msg.Command.FETCH_RES); const id = msg.fetchResId; @@ -111,7 +111,7 @@ class FetchRequest { start() { log("dispatch FETCH_REQ", this.id, this.url); - const res = dispatch.sendMsg("fetch", { + const res = pubInternal("fetch", { command: pb.Msg.Command.FETCH_REQ, fetchReqId: this.id, fetchReqUrl: this.url diff --git a/os.ts b/os.ts index 2817a97cc4..87f8061ff7 100644 --- a/os.ts +++ b/os.ts @@ -1,12 +1,12 @@ // Copyright 2018 Ryan Dahl // All rights reserved. MIT License. import { ModuleInfo } from "./types"; -import { sendMsg } from "./dispatch"; +import { pubInternal } from "./dispatch"; import { main as pb } from "./msg.pb"; import { assert } from "./util"; export function exit(exitCode = 0): void { - sendMsg("os", { + pubInternal("os", { command: pb.Msg.Command.EXIT, exitCode }); @@ -16,7 +16,7 @@ export function codeFetch( moduleSpecifier: string, containingFile: string ): ModuleInfo { - const res = sendMsg("os", { + const res = pubInternal("os", { command: pb.Msg.Command.CODE_FETCH, codeFetchModuleSpecifier: moduleSpecifier, codeFetchContainingFile: containingFile @@ -35,7 +35,7 @@ export function codeCache( sourceCode: string, outputCode: string ): void { - sendMsg("os", { + pubInternal("os", { command: pb.Msg.Command.CODE_CACHE, codeCacheFilename: filename, codeCacheSourceCode: sourceCode, @@ -44,7 +44,7 @@ export function codeCache( } export function readFileSync(filename: string): Uint8Array { - const res = sendMsg("os", { + const res = pubInternal("os", { command: pb.Msg.Command.READ_FILE_SYNC, readFileSyncFilename: filename }); @@ -56,7 +56,7 @@ export function writeFileSync( data: Uint8Array, perm: number ): void { - sendMsg("os", { + pubInternal("os", { command: pb.Msg.Command.WRITE_FILE_SYNC, writeFileSyncFilename: filename, writeFileSyncData: data, diff --git a/timers.ts b/timers.ts index 6fa0e7a435..136ae745cf 100644 --- a/timers.ts +++ b/timers.ts @@ -1,7 +1,7 @@ // Copyright 2018 Ryan Dahl // All rights reserved. MIT License. import { main as pb } from "./msg.pb"; -import * as dispatch from "./dispatch"; +import { pubInternal, sub } from "./dispatch"; import { assert } from "./util"; let nextTimerId = 1; @@ -21,7 +21,7 @@ interface Timer { const timers = new Map(); export function initTimers() { - dispatch.sub("timers", onMessage); + sub("timers", onMessage); } function onMessage(payload: Uint8Array) { @@ -54,7 +54,7 @@ function setTimer( cb }; timers.set(timer.id, timer); - dispatch.sendMsg("timers", { + pubInternal("timers", { command: pb.Msg.Command.TIMER_START, timerStartId: timer.id, timerStartInterval: timer.interval, @@ -82,7 +82,7 @@ export function setInterval( } export function clearTimer(id: number) { - dispatch.sendMsg("timers", { + pubInternal("timers", { command: pb.Msg.Command.TIMER_CLEAR, timerClearId: id });