Skip to content

Commit

Permalink
fix yield
Browse files Browse the repository at this point in the history
  • Loading branch information
syusui-s authored and fiatjaf committed Dec 20, 2023
1 parent 8f03116 commit 8625d45
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export function relayConnect(url: string) {
return relay
}

async function yieldThread() {
return new Promise((resolve) => {
const ch = new MessageChannel();
ch.port1.addEventListener('message', () => resolve());
ch.port2.postMessage(0);
ch.port1.start();
});
}

export class Relay {
public readonly url: string
private _connected: boolean = false
Expand Down Expand Up @@ -117,7 +126,7 @@ export class Relay {
if (false === this.handleNext()) {
break
}
await Promise.resolve()
await yieldThread()
}
this.queueRunning = false
}
Expand Down

0 comments on commit 8625d45

Please sign in to comment.