Compare commits

..

No commits in common. "2832694cd5d11ee54a4ba74cef967384c7e58ad1" and "b42069231ce07f509fa261840180292e0f2b49be" have entirely different histories.

1 changed files with 8 additions and 11 deletions

View File

@ -52,7 +52,6 @@ function idFactory(start = 1) {
const getSwarmId = idFactory(); const getSwarmId = idFactory();
const getSocketId = idFactory(); const getSocketId = idFactory();
const getChannelId = idFactory(); const getChannelId = idFactory();
const getMessageId = idFactory();
addHandler("presentSeed", handlePresentSeed); addHandler("presentSeed", handlePresentSeed);
addHandler("join", handleJoin); addHandler("join", handleJoin);
@ -515,7 +514,7 @@ async function createProtomuxMessage(aq: ActiveQuery) {
const data = aq.callerInput.data; const data = aq.callerInput.data;
const defers = new Map<number, DeferredPromise<any>>(); const defers: { [action: string]: DeferredPromise<any> } = {};
const handleEncoding = (enabled: boolean) => { const handleEncoding = (enabled: boolean) => {
if (!enabled) { if (!enabled) {
@ -523,16 +522,14 @@ async function createProtomuxMessage(aq: ActiveQuery) {
} }
const update = async (action: string, args: any) => { const update = async (action: string, args: any) => {
const messageId = getMessageId(); await defers[action]?.promise;
const d = defer(); defers[action] = defer();
defers.set(messageId, d);
aq.sendUpdate({ aq.sendUpdate({
id: messageId,
action, action,
args, args,
}); });
const ret = (await d.promise) as any; const ret = await defers[action]?.promise;
if (ret[1]) { if (ret[1]) {
if (ret[1].buffer) { if (ret[1].buffer) {
args[0].buffer = b4a.from(ret[1].buffer); args[0].buffer = b4a.from(ret[1].buffer);
@ -559,12 +556,12 @@ async function createProtomuxMessage(aq: ActiveQuery) {
}; };
aq.setReceiveUpdate?.((data) => { aq.setReceiveUpdate?.((data) => {
if (data.action === "send") { if (["send", "destroy"].includes(data.action)) {
message.send(...data.args); message[data.action](...data.args);
return;
} }
defers.get(data.id)?.resolve(data.args); defers[data.action]?.resolve(data.args);
defers.delete(data.id);
}); });
if (data.onmessage) { if (data.onmessage) {