From dc60fe9f300043f191286ef804a365e16e455f87 Mon Sep 17 00:00:00 2001 From: andy finch Date: Thu, 13 Jun 2019 23:43:54 -0400 Subject: Refactor dispatch handling (#2452) Promise id is now created in core and passed back to JS. --- core/shared_queue.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'core/shared_queue.js') diff --git a/core/shared_queue.js b/core/shared_queue.js index 75f370ce4..b413f011e 100644 --- a/core/shared_queue.js +++ b/core/shared_queue.js @@ -151,14 +151,27 @@ SharedQueue Binary Layout function handleAsyncMsgFromRust(buf) { if (buf) { - asyncHandler(buf); + handleAsyncMsgFromRustInner(buf); } else { while ((buf = shift()) != null) { - asyncHandler(buf); + handleAsyncMsgFromRustInner(buf); } } } + function handleAsyncMsgFromRustInner(buf) { + // DataView to extract cmdId value. + const dataView = new DataView(buf.buffer, buf.byteOffset, 4); + const promiseId = dataView.getInt32(0); + // Uint8 buffer view shifted right and shortened 4 bytes to remove cmdId from view window. + const bufViewFinal = new Uint8Array( + buf.buffer, + buf.byteOffset + 4, + buf.byteLength - 4 + ); + asyncHandler(promiseId, bufViewFinal); + } + function dispatch(control, zeroCopy = null) { maybeInit(); // First try to push control to shared. -- cgit v1.2.3