Closed steliosrammos closed 6 months ago
Throw an error.
Crashes. In the snippet below, 'Before connect' and 'Before fetch' are logged, but 'After fetch' is not. No error is logged either.
import 'websocket-polyfill'; import { generatePrivateKey, getPublicKey } from 'nostr-tools'; import NDK, { NDKPrivateKeySigner } from '@nostr-dev-kit/ndk'; const privateKey = generatePrivateKey(); const hexpubkey = getPublicKey(privateKey); const signer = new NDKPrivateKeySigner(privateKey); const ndk = new NDK({ signer, explicitRelayUrls: ['ws://localhost:7780'] }); const main = async () => { console.log('Before connect'); await ndk.connect(); console.log('Before fetch'); const filter = { kinds: [5], authors: [hexpubkey] }; const result = await ndk.fetchEvent(filter, { closeOnEose: true }).catch(err => console.log(err)); console.log('After fetch', result); } main();
I know this is super old but this behaviour is expected. If you don't pass a timeout to the connect() function then it will just wait indefinitely to get a connection.
connect()
Expected Behaviour
Throw an error.
Actual Behaviour
Crashes. In the snippet below, 'Before connect' and 'Before fetch' are logged, but 'After fetch' is not. No error is logged either.
Reproducible code