nbd-wtf / nostr-tools

Tools for developing Nostr clients.
The Unlicense
678 stars 187 forks source link

Pool connections status #300

Open misovan opened 11 months ago

misovan commented 11 months ago

Is there a way to get status (readyState) of connections inside a SimplePool? Thanks

Egge21M commented 9 months ago

I used a "dirty" workaround for this, accessing the _conn property of the SimplePool instance directly. It works, but maybe we should add a getter for Connection state. I'll open a PR

fiatjaf commented 9 months ago

I think using the dirty workaround should be fine.

Egge21M commented 9 months ago

I think using the dirty workaround should be fine.

I disagree. _conn is a private field that will not even be shown by the LSP. Also accessing it directly is unsafe. A overwrite will render the pool instance useless. Also _conn holds many other private fields of the Relay Instance that are not of interest to the end user of the API.

I am working on a PR that adds a getter method to the class that will return a safe copy of only the connection state and exclude the other methods.