mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-02-13 03:14:36 +00:00
pool: prevent edge case with undefined subcloser.
This commit is contained in:
@@ -16,8 +16,7 @@ import { Relay } from './relay.ts'
|
||||
export type SubCloser = { close: (reason?: string) => void }
|
||||
|
||||
export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & {
|
||||
// automaticallyAuth takes a relay URL and should return null
|
||||
// in case that relay shouldn't be authenticated against
|
||||
// automaticallyAuth takes a relay URL and should return null in case that relay shouldn't be authenticated against
|
||||
// or a function to sign the AUTH event template otherwise (that function may still throw in case of failure)
|
||||
automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
|
||||
// onRelayConnectionFailure is called with the URL of a relay that failed the initial connection
|
||||
@@ -269,10 +268,13 @@ export class AbstractSimplePool {
|
||||
filter: Filter,
|
||||
params: Pick<SubscribeManyParams, 'label' | 'id' | 'onevent' | 'onclose' | 'maxWait' | 'onauth'>,
|
||||
): SubCloser {
|
||||
const subcloser = this.subscribe(relays, filter, {
|
||||
let subcloser: SubCloser
|
||||
subcloser = this.subscribe(relays, filter, {
|
||||
...params,
|
||||
oneose() {
|
||||
subcloser.close('closed automatically on eose')
|
||||
const reason = 'closed automatically on eose'
|
||||
if (subcloser) subcloser.close(reason)
|
||||
else params.onclose?.(relays.map(_ => reason))
|
||||
},
|
||||
})
|
||||
return subcloser
|
||||
|
||||
2
jsr.json
2
jsr.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nostr/tools",
|
||||
"version": "2.23.0",
|
||||
"version": "2.23.1",
|
||||
"exports": {
|
||||
".": "./index.ts",
|
||||
"./core": "./core.ts",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"type": "module",
|
||||
"name": "nostr-tools",
|
||||
"version": "2.23.0",
|
||||
"version": "2.23.1",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user