mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
Fix connect/close return types and race condition
This commit is contained in:
9
relay.ts
9
relay.ts
@@ -6,8 +6,8 @@ import {Filter, matchFilters} from './filter'
|
|||||||
export type Relay = {
|
export type Relay = {
|
||||||
url: string
|
url: string
|
||||||
status: number
|
status: number
|
||||||
connect: () => void
|
connect: () => Promise<void>
|
||||||
close: () => void
|
close: () => Promise<void>
|
||||||
sub: (filters: Filter[], opts: SubscriptionOptions) => Sub
|
sub: (filters: Filter[], opts: SubscriptionOptions) => Sub
|
||||||
publish: (event: Event) => Pub
|
publish: (event: Event) => Pub
|
||||||
on: (type: 'connect' | 'disconnect' | 'notice', cb: any) => void
|
on: (type: 'connect' | 'disconnect' | 'notice', cb: any) => void
|
||||||
@@ -257,10 +257,11 @@ export function relayInit(url: string): Relay {
|
|||||||
},
|
},
|
||||||
connect,
|
connect,
|
||||||
close(): Promise<void> {
|
close(): Promise<void> {
|
||||||
ws.close()
|
const result = new Promise<void>(resolve => {
|
||||||
return new Promise(resolve => {
|
|
||||||
resolveClose = resolve
|
resolveClose = resolve
|
||||||
})
|
})
|
||||||
|
ws.close()
|
||||||
|
return result
|
||||||
},
|
},
|
||||||
get status() {
|
get status() {
|
||||||
return ws?.readyState ?? 3
|
return ws?.readyState ?? 3
|
||||||
|
|||||||
Reference in New Issue
Block a user