From 4221b90c3febbe03a4b47e47248263741a0fdd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 14 Oct 2019 23:46:27 +0200 Subject: perf: eager poll async ops in Isolate (#3046) --- cli/js/dispatch_json.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'cli/js/dispatch_json.ts') diff --git a/cli/js/dispatch_json.ts b/cli/js/dispatch_json.ts index 572ec855a..890568409 100644 --- a/cli/js/dispatch_json.ts +++ b/cli/js/dispatch_json.ts @@ -75,11 +75,17 @@ export async function sendAsync( const promiseId = nextPromiseId(); args = Object.assign(args, { promiseId }); const promise = util.createResolvable(); - promiseTable.set(promiseId, promise); const argsUi8 = encode(args); - const resUi8 = core.dispatch(opId, argsUi8, zeroCopy); - util.assert(resUi8 == null); + const buf = core.dispatch(opId, argsUi8, zeroCopy); + if (buf) { + // Sync result. + const res = decode(buf); + promise.resolve(res); + } else { + // Async result. + promiseTable.set(promiseId, promise); + } const res = await promise; return unwrapResponse(res); -- cgit v1.2.3