summaryrefslogtreecommitdiff
path: root/core/examples/http_bench.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/examples/http_bench.js')
-rw-r--r--core/examples/http_bench.js16
1 files changed, 7 insertions, 9 deletions
diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js
index 8eb764b55..7e678aecd 100644
--- a/core/examples/http_bench.js
+++ b/core/examples/http_bench.js
@@ -13,7 +13,6 @@ const responseBuf = new Uint8Array(
.map(c => c.charCodeAt(0))
);
const promiseMap = new Map();
-let nextPromiseId = 1;
function assert(cond) {
if (!cond) {
@@ -37,8 +36,8 @@ const scratchBytes = new Uint8Array(
);
assert(scratchBytes.byteLength === 4 * 4);
-function send(promiseId, opId, arg, zeroCopy = null) {
- scratch32[0] = promiseId;
+function send(isSync, opId, arg, zeroCopy = null) {
+ scratch32[0] = isSync;
scratch32[1] = opId;
scratch32[2] = arg;
scratch32[3] = -1;
@@ -47,10 +46,9 @@ function send(promiseId, opId, arg, zeroCopy = null) {
/** Returns Promise<number> */
function sendAsync(opId, arg, zeroCopy = null) {
- const promiseId = nextPromiseId++;
+ const promiseId = send(false, opId, arg, zeroCopy);
const p = createResolvable();
promiseMap.set(promiseId, p);
- send(promiseId, opId, arg, zeroCopy);
return p;
}
@@ -58,7 +56,7 @@ function recordFromBuf(buf) {
assert(buf.byteLength === 16);
const buf32 = new Int32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
return {
- promiseId: buf32[0],
+ isSync: !!buf32[0],
opId: buf32[1],
arg: buf32[2],
result: buf32[3]
@@ -67,14 +65,14 @@ function recordFromBuf(buf) {
/** Returns i32 number */
function sendSync(opId, arg) {
- const buf = send(0, opId, arg);
+ const buf = send(true, opId, arg);
const record = recordFromBuf(buf);
return record.result;
}
-function handleAsyncMsgFromRust(buf) {
+function handleAsyncMsgFromRust(promiseId, buf) {
const record = recordFromBuf(buf);
- const { promiseId, result } = record;
+ const { result } = record;
const p = promiseMap.get(promiseId);
promiseMap.delete(promiseId);
p.resolve(result);