Skip to content
Permalink
Browse files

cleanups

  • Loading branch information...
ry committed Mar 15, 2019
1 parent cb3ccb9 commit 39e55e7df1683b440cb24efb117ad47a800a4abb
Showing with 14 additions and 15 deletions.
  1. +11 −12 core/http_bench.js
  2. +2 −2 core/isolate.rs
  3. +1 −1 core/shared_queue.js
@@ -6,23 +6,21 @@ const OP_ACCEPT = 2;
const OP_READ = 3;
const OP_WRITE = 4;
const OP_CLOSE = 5;

function assert(cond) {
if (!cond) {
throw Error("assert");
}
}

const requestBuf = new Uint8Array(64 * 1024);
const responseBuf = new Uint8Array(
"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n"
.split("")
.map(c => c.charCodeAt(0))
);

const promiseMap = new Map();
let nextPromiseId = 1;

function assert(cond) {
if (!cond) {
throw Error("assert");
}
}

function createResolvable() {
let methods;
const promise = new Promise((resolve, reject) => {
@@ -57,15 +55,16 @@ function send(promiseId, opId, arg, zeroCopy = null) {
}

/** Returns Promise<number> */
function sendAsync(opId, arg, zeroCopyData) {
function sendAsync(opId, arg, zeroCopy = null) {
const promiseId = nextPromiseId++;
const p = createResolvable();
promiseMap.set(promiseId, p);
send(promiseId, opId, arg, zeroCopyData);
send(promiseId, opId, arg, zeroCopy);
return p;
}

function recordFromBuf(buf) {
assert(buf.byteLength === 16);
const buf32 = new Int32Array(buf.buffer, buf.byteOffset, buf.byteLength);
return {
promiseId: buf32[0],
@@ -83,7 +82,7 @@ function recv() {
return recordFromBuf(buf);
}

/** Returns u32 number */
/** Returns i32 number */
function sendSync(opId, arg) {
send(0, opId, arg);
const record = recv();
@@ -142,7 +141,7 @@ async function serve(rid) {
}

async function main() {
Deno.setAsyncHandler(handleAsyncMsgFromRust);
Deno._setAsyncHandler(handleAsyncMsgFromRust);

libdeno.print("http_bench.js start\n");

@@ -474,7 +474,7 @@ mod tests {
"setup.js",
r#"
let nrecv = 0;
Deno.setAsyncHandler((buf) => {
Deno._setAsyncHandler((buf) => {
nrecv++;
});
function assertEq(actual, expected) {
@@ -524,7 +524,7 @@ mod tests {
"setup.js",
r#"
let nrecv = 0;
Deno.setAsyncHandler((buf) => {
Deno._setAsyncHandler((buf) => {
assert(buf.byteLength === 1);
assert(buf[0] === 43);
nrecv++;
@@ -115,7 +115,7 @@
libdeno.recv(handleAsyncMsgFromRust);
}

window.Deno.setAsyncHandler = setAsyncHandler;
window.Deno._setAsyncHandler = setAsyncHandler;
window.Deno._sharedQueue = {
head,
numRecords,

0 comments on commit 39e55e7

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.