mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
update close() usage
Signed-off-by: BilligsterUser <billigsteruser@protonmail.com>
This commit is contained in:
@@ -120,7 +120,7 @@ let event = await relay.get({
|
|||||||
ids: ['44e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245']
|
ids: ['44e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245']
|
||||||
})
|
})
|
||||||
|
|
||||||
await relay.close()
|
relay.close()
|
||||||
```
|
```
|
||||||
|
|
||||||
To use this on Node.js you first must install `websocket-polyfill` and import it:
|
To use this on Node.js you first must install `websocket-polyfill` and import it:
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ let relays = [
|
|||||||
'wss://nostr.zebedee.cloud/'
|
'wss://nostr.zebedee.cloud/'
|
||||||
]
|
]
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(() => {
|
||||||
await pool.close([
|
pool.close([
|
||||||
...relays,
|
...relays,
|
||||||
'wss://nostr-relay.untethr.me',
|
'wss://nostr-relay.untethr.me',
|
||||||
'wss://offchain.pub',
|
'wss://offchain.pub',
|
||||||
|
|||||||
8
pool.ts
8
pool.ts
@@ -12,13 +12,11 @@ export class SimplePool {
|
|||||||
this._conn = {}
|
this._conn = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async close(relays: string[]): Promise<void> {
|
close(relays: string[]): void {
|
||||||
await Promise.all(
|
relays.map(url => {
|
||||||
relays.map(async url => {
|
|
||||||
let relay = this._conn[normalizeURL(url)]
|
let relay = this._conn[normalizeURL(url)]
|
||||||
if (relay) await relay.close()
|
if (relay) relay.close()
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureRelay(url: string): Promise<Relay> {
|
async ensureRelay(url: string): Promise<Relay> {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ beforeAll(() => {
|
|||||||
relay.connect()
|
relay.connect()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(() => {
|
||||||
await relay.close()
|
relay.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('connectivity', () => {
|
test('connectivity', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user