summaryrefslogtreecommitdiff
path: root/js/dispatch.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-09-27 17:33:10 -0400
committerGitHub <noreply@github.com>2018-09-27 17:33:10 -0400
commitd38ccfc6dcb8643daa4f9e695d47a79cf068f90e (patch)
treed36ad2934e8550242d50e866f4ad2b6c303646b7 /js/dispatch.ts
parentbf93ca54dd85686c7b93a6189913e48e10de8dcf (diff)
Support zero-copy data in libdeno.send(). (#838)
This is a large API refactor of deno.h which replaces deno_send() and deno_set_response() with deno_respond(). It also adds a req_id parameter to the deno_recv_cb. Make writeFile/writeFileSync use it.
Diffstat (limited to 'js/dispatch.ts')
-rw-r--r--js/dispatch.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/js/dispatch.ts b/js/dispatch.ts
index 037b77a85..9257be767 100644
--- a/js/dispatch.ts
+++ b/js/dispatch.ts
@@ -28,10 +28,11 @@ export function handleAsyncMsgFromRust(ui8: Uint8Array) {
export function sendAsync(
builder: flatbuffers.Builder,
msgType: fbs.Any,
- msg: flatbuffers.Offset
+ msg: flatbuffers.Offset,
+ data?: ArrayBufferView
): Promise<fbs.Base> {
maybePushTrace(msgType, false); // add to trace if tracing
- const [cmdId, resBuf] = sendInternal(builder, msgType, msg, false);
+ const [cmdId, resBuf] = sendInternal(builder, msgType, msg, data, false);
util.assert(resBuf == null);
const promise = util.createResolvable<fbs.Base>();
promiseTable.set(cmdId, promise);
@@ -42,16 +43,16 @@ export function sendAsync(
export function sendSync(
builder: flatbuffers.Builder,
msgType: fbs.Any,
- msg: flatbuffers.Offset
+ msg: flatbuffers.Offset,
+ data?: ArrayBufferView
): null | fbs.Base {
maybePushTrace(msgType, true); // add to trace if tracing
- const [cmdId, resBuf] = sendInternal(builder, msgType, msg, true);
+ const [cmdId, resBuf] = sendInternal(builder, msgType, msg, data, true);
util.assert(cmdId >= 0);
if (resBuf == null) {
return null;
} else {
const u8 = new Uint8Array(resBuf!);
- // console.log("recv sync message", util.hexdump(u8));
const bb = new flatbuffers.ByteBuffer(u8);
const baseRes = fbs.Base.getRootAsBase(bb);
errors.maybeThrowError(baseRes);
@@ -63,6 +64,7 @@ function sendInternal(
builder: flatbuffers.Builder,
msgType: fbs.Any,
msg: flatbuffers.Offset,
+ data: undefined | ArrayBufferView,
sync = true
): [number, null | Uint8Array] {
const cmdId = nextCmdId++;
@@ -73,5 +75,5 @@ function sendInternal(
fbs.Base.addCmdId(builder, cmdId);
builder.finish(fbs.Base.endBase(builder));
- return [cmdId, libdeno.send(builder.asUint8Array())];
+ return [cmdId, libdeno.send(builder.asUint8Array(), data)];
}