*make message encoding/decoding async for use with the kernel
This commit is contained in:
parent
bbe30a3de5
commit
e7aa69a59b
14
index.js
14
index.js
|
@ -205,34 +205,34 @@ class Channel {
|
||||||
type,
|
type,
|
||||||
encoding,
|
encoding,
|
||||||
onmessage,
|
onmessage,
|
||||||
recv(state, session) {
|
async recv(state, session) {
|
||||||
session._track(m.onmessage(encoding.decode(state), session));
|
session._track(m.onmessage(await encoding.decode(state), session));
|
||||||
},
|
},
|
||||||
send(m, session = s) {
|
async send(m, session = s) {
|
||||||
if (session.closed === true) return false;
|
if (session.closed === true) return false;
|
||||||
|
|
||||||
const mux = session._mux;
|
const mux = session._mux;
|
||||||
const state = { buffer: null, start: 0, end: typeLen };
|
const state = { buffer: null, start: 0, end: typeLen };
|
||||||
|
|
||||||
if (mux._batch !== null) {
|
if (mux._batch !== null) {
|
||||||
encoding.preencode(state, m);
|
await encoding.preencode(state, m);
|
||||||
state.buffer = mux._alloc(state.end);
|
state.buffer = mux._alloc(state.end);
|
||||||
|
|
||||||
c.uint.encode(state, type);
|
c.uint.encode(state, type);
|
||||||
encoding.encode(state, m);
|
await encoding.encode(state, m);
|
||||||
|
|
||||||
mux._pushBatch(session._localId, state.buffer);
|
mux._pushBatch(session._localId, state.buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.uint.preencode(state, session._localId);
|
c.uint.preencode(state, session._localId);
|
||||||
encoding.preencode(state, m);
|
await encoding.preencode(state, m);
|
||||||
|
|
||||||
state.buffer = mux._alloc(state.end);
|
state.buffer = mux._alloc(state.end);
|
||||||
|
|
||||||
c.uint.encode(state, session._localId);
|
c.uint.encode(state, session._localId);
|
||||||
c.uint.encode(state, type);
|
c.uint.encode(state, type);
|
||||||
encoding.encode(state, m);
|
await encoding.encode(state, m);
|
||||||
|
|
||||||
return mux.stream.write(state.buffer);
|
return mux.stream.write(state.buffer);
|
||||||
},
|
},
|
||||||
|
|
Reference in New Issue