*make message encoding/decoding async for use with the kernel

This commit is contained in:
Derrick Hammer 2023-04-08 21:09:49 -04:00
parent bbe30a3de5
commit e7aa69a59b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 7 deletions

View File

@ -205,34 +205,34 @@ class Channel {
type,
encoding,
onmessage,
recv(state, session) {
session._track(m.onmessage(encoding.decode(state), session));
async recv(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;
const mux = session._mux;
const state = { buffer: null, start: 0, end: typeLen };
if (mux._batch !== null) {
encoding.preencode(state, m);
await encoding.preencode(state, m);
state.buffer = mux._alloc(state.end);
c.uint.encode(state, type);
encoding.encode(state, m);
await encoding.encode(state, m);
mux._pushBatch(session._localId, state.buffer);
return true;
}
c.uint.preencode(state, session._localId);
encoding.preencode(state, m);
await encoding.preencode(state, m);
state.buffer = mux._alloc(state.end);
c.uint.encode(state, session._localId);
c.uint.encode(state, type);
encoding.encode(state, m);
await encoding.encode(state, m);
return mux.stream.write(state.buffer);
},