-
Notifications
You must be signed in to change notification settings - Fork 94
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
No way to implement external events due to blocking recv_event #109
Comments
For example, to cleanly stop the main event loop, you have to create a new thread and move This is fine, but when you need access to I'd love to see a different way to receive events that enables this flow to work. |
Clean shutdowns triggered by external events are probably the thorniest situation caused by the current blocking There are a couple of ways to handle other event sources. If all you need is to trigger Discord API calls based on events from other sources, run them in their own thread and use an Connecting to voice based on an external event is another point of difficulty. I intend to analyze all this at some point and figure out what can be done. The main obstacle is building on top of the underlying websocket and TLS wrappers which aren't immediately amenable to non-blocking or asynchronous I/O. I also think tokio is too young and complicates both library and client code too thoroughly to be worth implementing just yet, though it has a very promising future. |
If possible, the simplest solution could be to not take a mutable reference in recv_event. Sadly, I suspect an upstream repository has it that way? |
the latest websocket has a .set_nonblocking() method on streams and clients. because sslstreams cannot be split anymore (its unsafe), i was thinking about moving the entire client into the keepalive thread, handling all heartbeat and reconnecting logic there, and adding a second mpsc channel to send events back to the connection object, which could be read in both blocking and nonblocking ways from the connection object. any thoughts? i do agree that async would be nice, but its still pretty early and awkward right now, and i feel like its important to keep having sync libs too. |
I think anything that actually makes this possible seems fantastic. |
If you can make it work while keeping close to the current interface, I would happily accept that PR. |
Hi everyone! Has there been any progress on this since the issue was last updated? I've run into the same scenario as @ascclemens describes in their final paragraph regarding the blocking call to |
Right now the only way to poll events from a Connection is to use recv_event, which is a blocking operation. As a result, it's impossible right now to implement a bot that listens on external events and produces Discord commands based on those events.
To fix this, there should be either a non-blocking alternative to recv_event, or a Future/Stream interface for streaming the events.
The text was updated successfully, but these errors were encountered: