diff options
Diffstat (limited to 'core/examples/http_bench.js')
-rw-r--r-- | core/examples/http_bench.js | 25 |
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; |