Skip to content

Commit

Permalink
Rename sendMsg to pubInternal (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkingxue authored and ry committed Jun 5, 2018
1 parent 8094c74 commit 78124cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions os.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2018 Ryan Dahl <[email protected]>
// 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
});
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
});
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions timers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018 Ryan Dahl <[email protected]>
// 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;
Expand All @@ -21,7 +21,7 @@ interface Timer {
const timers = new Map<number, Timer>();

export function initTimers() {
dispatch.sub("timers", onMessage);
sub("timers", onMessage);
}

function onMessage(payload: Uint8Array) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
});
Expand Down

0 comments on commit 78124cd

Please sign in to comment.