fix: need to loop over all protomux message args and await any promises
This commit is contained in:
parent
411d35154f
commit
3a4cfd45a6
17
src/index.ts
17
src/index.ts
|
@ -576,10 +576,17 @@ async function handleCreateProtomuxMessage(aq: ActiveQuery) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.onmessage) {
|
if (data.onmessage) {
|
||||||
data.onmessage = (...args: any) => {
|
data.onmessage = async (...args: any) => {
|
||||||
|
for (let i = 0; i < args.length; i++) {
|
||||||
|
if (isPromise(args[i])) {
|
||||||
|
args[i] = await args[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
args = args.filter(
|
args = args.filter(
|
||||||
(item: any) => item?.constructor.name.toLowerCase() !== "channel",
|
(item: any) => item?.constructor.name.toLowerCase() !== "channel",
|
||||||
);
|
);
|
||||||
|
|
||||||
aq.sendUpdate({
|
aq.sendUpdate({
|
||||||
action: "onmessage",
|
action: "onmessage",
|
||||||
args,
|
args,
|
||||||
|
@ -622,3 +629,11 @@ function getSwarmToSwarmId(swarm: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
function isPromise(obj: Promise<any>) {
|
||||||
|
return (
|
||||||
|
!!obj &&
|
||||||
|
(typeof obj === "object" || typeof obj === "function") &&
|
||||||
|
typeof obj.then === "function"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue