First pass at json ops in core (#7033)

Adds Deno.core.jsonOpSync and Deno.core.jsonOpAsync
This commit is contained in:
Ryan Dahl 2020-08-20 09:45:59 -04:00 committed by GitHub
parent be1e7ab532
commit 0095611af9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 151 additions and 20 deletions

View file

@ -80,12 +80,14 @@ function handleAsyncMsgFromRust(buf) {
/** Listens on 0.0.0.0:4500, returns rid. */
function listen() {
return sendSync(ops["listen"], -1);
const { rid } = Deno.core.jsonOpSync("listen", {});
return rid;
}
/** Accepts a connection, returns rid. */
function accept(rid) {
return sendAsync(ops["accept"], rid);
async function accept(serverRid) {
const { rid } = await Deno.core.jsonOpAsync("accept", { rid: serverRid });
return rid;
}
/**
@ -124,9 +126,8 @@ let ops;
async function main() {
ops = Deno.core.ops();
for (const opName in ops) {
Deno.core.setAsyncHandler(ops[opName], handleAsyncMsgFromRust);
}
Deno.core.setAsyncHandler(ops["read"], handleAsyncMsgFromRust);
Deno.core.setAsyncHandler(ops["write"], handleAsyncMsgFromRust);
Deno.core.print("http_bench.js start\n");