diff options
author | Andy Finch <andyfinch7@gmail.com> | 2020-01-17 08:26:11 -0500 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2020-01-17 08:26:11 -0500 |
commit | fe5662058e0c7767e7b2724451f9d5a3f133ffbf (patch) | |
tree | be43744898f64af6605246ba95ede55a869f7ab4 /core/shared_queue.js | |
parent | d8ad81d3fb5b4b9502ea021edfc99201538553e6 (diff) |
feat: support individual async handler for each op (#3690)
Diffstat (limited to 'core/shared_queue.js')
-rw-r--r-- | core/shared_queue.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/core/shared_queue.js b/core/shared_queue.js index 430261511..093cc223f 100644 --- a/core/shared_queue.js +++ b/core/shared_queue.js @@ -38,6 +38,9 @@ SharedQueue Binary Layout let sharedBytes; let shared32; + + let asyncHandlers; + let initialized = false; function maybeInit() { @@ -54,6 +57,7 @@ SharedQueue Binary Layout assert(shared32 == null); sharedBytes = new Uint8Array(shared); shared32 = new Int32Array(shared); + asyncHandlers = []; // Callers should not call Deno.core.recv, use setAsyncHandler. Deno.core.recv(handleAsyncMsgFromRust); } @@ -157,24 +161,24 @@ SharedQueue Binary Layout return [opId, buf]; } - let asyncHandler; - function setAsyncHandler(cb) { + function setAsyncHandler(opId, cb) { maybeInit(); - assert(asyncHandler == null); - asyncHandler = cb; + assert(opId != null); + asyncHandlers[opId] = cb; } function handleAsyncMsgFromRust(opId, buf) { if (buf) { // This is the overflow_response case of deno::Isolate::poll(). - asyncHandler(opId, buf); + asyncHandlers[opId](buf); } else { while (true) { const opIdBuf = shift(); if (opIdBuf == null) { break; } - asyncHandler(...opIdBuf); + assert(asyncHandlers[opIdBuf[0]] != null); + asyncHandlers[opIdBuf[0]](opIdBuf[1]); } } } |