mirror of
https://github.com/denoland/deno.git
synced 2025-08-01 09:32:28 +00:00
Add 'command id' field to messages
This allows for correlating response messages to the command message that caused them.
This commit is contained in:
parent
7c5db007de
commit
8a17db8266
5 changed files with 31 additions and 13 deletions
15
js/main.ts
15
js/main.ts
|
@ -11,10 +11,19 @@ import { assert } from "./util";
|
|||
const globalEval = eval;
|
||||
const window = globalEval("this");
|
||||
|
||||
function startMsg(): ArrayBuffer {
|
||||
let cmdIdCounter = 0;
|
||||
function assignCmdId(): number {
|
||||
// TODO(piscisaureus) Safely re-use so they don't overflow.
|
||||
const cmdId = ++cmdIdCounter;
|
||||
assert(cmdId < 2 ** 32, "cmdId overflow");
|
||||
return cmdId;
|
||||
}
|
||||
|
||||
function startMsg(cmdId: number): ArrayBuffer {
|
||||
const builder = new flatbuffers.Builder();
|
||||
const msg = fbs.Start.createStart(builder, 0);
|
||||
fbs.Base.startBase(builder);
|
||||
fbs.Base.addCmdId(builder, cmdId);
|
||||
fbs.Base.addMsg(builder, msg);
|
||||
fbs.Base.addMsgType(builder, fbs.Any.Start);
|
||||
builder.finish(fbs.Base.endBase(builder));
|
||||
|
@ -27,7 +36,8 @@ window["denoMain"] = () => {
|
|||
// First we send an empty "Start" message to let the privlaged side know we
|
||||
// are ready. The response should be a "StartRes" message containing the CLI
|
||||
// argv and other info.
|
||||
const res = deno.send(startMsg());
|
||||
const cmdId = assignCmdId();
|
||||
const res = deno.send(startMsg(cmdId));
|
||||
|
||||
// TODO(ry) Remove this conditional once main.rs gets up to speed.
|
||||
if (res == null) {
|
||||
|
@ -39,6 +49,7 @@ window["denoMain"] = () => {
|
|||
// Deserialize res into startResMsg.
|
||||
const bb = new flatbuffers.ByteBuffer(new Uint8Array(res));
|
||||
const base = fbs.Base.getRootAsBase(bb);
|
||||
assert(base.cmdId() === cmdId);
|
||||
assert(fbs.Any.StartRes === base.msgType());
|
||||
const startResMsg = new fbs.StartRes();
|
||||
assert(base.msg(startResMsg) != null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue