summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingchen Xue <yingchenxue@qq.com>2018-06-05 16:10:27 +0800
committerRyan Dahl <ry@tinyclouds.org>2018-06-05 10:10:27 +0200
commit78124cd45f5b5efe1f06e82554ff09273b75b050 (patch)
tree646f8d233b5827d4b790d4f97ddce977eb1870c5
parent8094c7421b50d3cbbc0eace6d376d7ed31b3cfa1 (diff)
Rename sendMsg to pubInternal (#136)
-rw-r--r--dispatch.ts3
-rw-r--r--fetch.ts6
-rw-r--r--os.ts12
-rw-r--r--timers.ts8
4 files changed, 14 insertions, 15 deletions
diff --git a/dispatch.ts b/dispatch.ts
index 01bd58bed..1ed6af71e 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 e0ac4db71..42acfa22f 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 2817a97cc..87f8061ff 100644
--- a/os.ts
+++ b/os.ts
@@ -1,12 +1,12 @@
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// 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 6fa0e7a43..136ae745c 100644
--- a/timers.ts
+++ b/timers.ts
@@ -1,7 +1,7 @@
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// 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<number, Timer>();
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
});