mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 15:44:36 +00:00
First pass at json ops in core (#7033)
Adds Deno.core.jsonOpSync and Deno.core.jsonOpAsync
This commit is contained in:
parent
be1e7ab532
commit
0095611af9
5 changed files with 151 additions and 20 deletions
|
@ -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");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue