summaryrefslogtreecommitdiff
path: root/core/examples/http_bench.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-10-14 23:46:27 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-10-14 17:46:27 -0400
commit4221b90c3febbe03a4b47e47248263741a0fdd4a (patch)
tree0c16487c197863fb1223f37a9c589905517dfdcd /core/examples/http_bench.js
parent605659535794ca0d8fe3ee4ea5857b418d7ce091 (diff)
perf: eager poll async ops in Isolate (#3046)
Diffstat (limited to 'core/examples/http_bench.js')
-rw-r--r--core/examples/http_bench.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js
index a7142b09d..f553d4800 100644
--- a/core/examples/http_bench.js
+++ b/core/examples/http_bench.js
@@ -43,11 +43,25 @@ function send(promiseId, opId, arg, zeroCopy = null) {
function sendAsync(opId, arg, zeroCopy = null) {
const promiseId = nextPromiseId++;
const p = createResolvable();
- promiseMap.set(promiseId, p);
- send(promiseId, opId, arg, zeroCopy);
+ const buf = send(promiseId, opId, arg, zeroCopy);
+ if (buf) {
+ const record = recordFromBuf(buf);
+ // Sync result.
+ p.resolve(record.result);
+ } else {
+ // Async result.
+ promiseMap.set(promiseId, p);
+ }
return p;
}
+/** Returns i32 number */
+function sendSync(opId, arg) {
+ const buf = send(0, opId, arg);
+ const record = recordFromBuf(buf);
+ return record.result;
+}
+
function recordFromBuf(buf) {
assert(buf.byteLength === 3 * 4);
const buf32 = new Int32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
@@ -58,13 +72,6 @@ function recordFromBuf(buf) {
};
}
-/** Returns i32 number */
-function sendSync(opId, arg) {
- const buf = send(0, opId, arg);
- const record = recordFromBuf(buf);
- return record.result;
-}
-
function handleAsyncMsgFromRust(opId, buf) {
const record = recordFromBuf(buf);
const { promiseId, result } = record;