Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk.connect is asynchronous and doesn't respect timeout #290

Open
ktecho opened this issue Dec 23, 2024 · 1 comment
Open

ndk.connect is asynchronous and doesn't respect timeout #290

ktecho opened this issue Dec 23, 2024 · 1 comment

Comments

@ktecho
Copy link

ktecho commented Dec 23, 2024

When trying to publish events, I try doing this:

await ndk.connect(5000);
const ndkEvent = new NDKEvent(ndk);
ndkEvent.xxx = xxx
await ndkEvent.publish()

That fails from time to time with NDKPublishError: Not enough relays received the event.

If I wait for 5 seconds, then it always works:

await ndk.connect(5000);
await new Promise(resolve => setTimeout(resolve, 5000));
const ndkEvent = new NDKEvent(ndk);
ndkEvent.xxx = xxx
await ndkEvent.publish()

I think that's a bug, because the timeout should wait 5 seconds before returning. I see this in ndk's code: If the timeout is reached, the connection will be continued to be established in the background.

@Giszmo
Copy link

Giszmo commented Feb 11, 2025

I'm trying to understand NDK and find the documentation lacking but Gemini 2.0 Pro told me that even with timeout, the connect() method probably does not block until any connection was established and guessed it would emit events when that happens.

I tried to understand Pablo's highlighter code and couldn't find any such event handling. In fact his code looks like working under the same assumptions as @ktecho's example above, unless I missed something ...

In flockstr I see ndk.pool.on("connect", () => console.log("✅ connected")); but it's only for debugging, not to signal readiness to publish.

I saw mention of some caching that allows for async handling of publishing but no example neither.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants