mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
fix yield
This commit is contained in:
committed by
fiatjaf_
parent
8f03116687
commit
8625d45152
11
relay.ts
11
relay.ts
@@ -12,6 +12,15 @@ export function relayConnect(url: string) {
|
|||||||
return relay
|
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 {
|
export class Relay {
|
||||||
public readonly url: string
|
public readonly url: string
|
||||||
private _connected: boolean = false
|
private _connected: boolean = false
|
||||||
@@ -117,7 +126,7 @@ export class Relay {
|
|||||||
if (false === this.handleNext()) {
|
if (false === this.handleNext()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
await Promise.resolve()
|
await yieldThread()
|
||||||
}
|
}
|
||||||
this.queueRunning = false
|
this.queueRunning = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user