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