remove untilOpen promise that was causing memory leaks when a connection was never opened.

This commit is contained in:
fiatjaf
2023-02-14 11:24:06 -03:00
parent c42cd925ce
commit 32793146a4
3 changed files with 141 additions and 7 deletions

View File

@@ -38,10 +38,6 @@ export type SubscriptionOptions = {
export function relayInit(url: string): Relay {
var ws: WebSocket
var resolveClose: () => void
var setOpen: (value: PromiseLike<void> | void) => void
var untilOpen = new Promise<void>(resolve => {
setOpen = resolve
})
var openSubs: {[id: string]: {filters: Filter[]} & SubscriptionOptions} = {}
var listeners: {
connect: Array<() => void>
@@ -74,7 +70,6 @@ export function relayInit(url: string): Relay {
ws.onopen = () => {
listeners.connect.forEach(cb => cb())
setOpen()
resolve()
}
ws.onerror = () => {
@@ -171,7 +166,6 @@ export function relayInit(url: string): Relay {
async function trySend(params: [string, ...any]) {
let msg = JSON.stringify(params)
await untilOpen
try {
ws.send(msg)
} catch (err) {