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 SubCloser = { close: (reason?: string) => void }
|
||||||
|
|
||||||
export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & {
|
export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & {
|
||||||
// automaticallyAuth takes a relay URL and should return null
|
// automaticallyAuth takes a relay URL and should return null in case that relay shouldn't be authenticated against
|
||||||
// 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)
|
// 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>)
|
automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
|
||||||
// onRelayConnectionFailure is called with the URL of a relay that failed the initial connection
|
// onRelayConnectionFailure is called with the URL of a relay that failed the initial connection
|
||||||
@@ -269,10 +268,13 @@ export class AbstractSimplePool {
|
|||||||
filter: Filter,
|
filter: Filter,
|
||||||
params: Pick<SubscribeManyParams, 'label' | 'id' | 'onevent' | 'onclose' | 'maxWait' | 'onauth'>,
|
params: Pick<SubscribeManyParams, 'label' | 'id' | 'onevent' | 'onclose' | 'maxWait' | 'onauth'>,
|
||||||
): SubCloser {
|
): SubCloser {
|
||||||
const subcloser = this.subscribe(relays, filter, {
|
let subcloser: SubCloser
|
||||||
|
subcloser = this.subscribe(relays, filter, {
|
||||||
...params,
|
...params,
|
||||||
oneose() {
|
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
|
return subcloser
|
||||||
|
|||||||
2
jsr.json
2
jsr.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.23.0",
|
"version": "2.23.1",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.23.0",
|
"version": "2.23.1",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user