Fix race condition in switchRelays
This commit is contained in:
@@ -496,10 +496,16 @@ export class Nip46Broker extends Emitter {
|
|||||||
if (relays && relays.length > 0) {
|
if (relays && relays.length > 0) {
|
||||||
this.params.relays = relays.map(normalizeRelayUrl)
|
this.params.relays = relays.map(normalizeRelayUrl)
|
||||||
|
|
||||||
this.sender.stop()
|
const oldSender = this.sender
|
||||||
this.sender = this.makeSender()
|
const oldReceiver = this.receiver
|
||||||
|
|
||||||
this.receiver.stop()
|
// Let any in-flight requests finish first
|
||||||
|
setTimeout(() => {
|
||||||
|
oldSender.stop()
|
||||||
|
oldReceiver.stop()
|
||||||
|
}, 5_000)
|
||||||
|
|
||||||
|
this.sender = this.makeSender()
|
||||||
this.receiver = this.makeReceiver()
|
this.receiver = this.makeReceiver()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user