1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

Rename sendMsg to pubInternal (#136)

This commit is contained in:
Yingchen Xue 2018-06-05 16:10:27 +08:00 committed by Ryan Dahl
parent 8094c7421b
commit 78124cd45f
4 changed files with 14 additions and 15 deletions

View file

@ -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);

View file

@ -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

12
os.ts
View file

@ -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,

View file

@ -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
});