-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add an async socket.io API #180
Conversation
The new code and types added by this commit build upon the structure of the asynchronous engine.io version and expose a new AsyncClient and AsyncClientBuilder
Codecov Report
@@ Coverage Diff @@
## main #180 +/- ##
==========================================
- Coverage 91.31% 90.87% -0.45%
==========================================
Files 31 37 +6
Lines 3764 4535 +771
==========================================
+ Hits 3437 4121 +684
- Misses 327 414 +87
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main concerns:
- consider async callback in a separate feature
- tests don't test to make sure the callbacks function
- version bump
socketio/Cargo.toml
Outdated
|
||
[features] | ||
default = ["async"] # TODO: remove this before merging, just here so that test run through | ||
async = ["rust_engineio/async", "tokio", "futures-util", "async-stream"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Put async callbacks behind a feature. Personally don't find async callbacks very ergonomic. Putting them behind a feature would allow us to explore other alternatives in a non-breaking fashion.
Current open points:
|
@nshaaban-cPacket What alternatives to async callbacks would you consider? A possible alternative would be to somehow use the implementation of
|
I added the |
Either:
|
Sorry it took so long to review, didn't see that you re-requested review.
May want to remove those tests that aren't actually testing so the coverage number is accurate. |
.map(|value| match value { | ||
Value::String(ev) => ev, | ||
_ => "message", | ||
}) | ||
.unwrap_or("message") | ||
.into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(|value| match value { | |
Value::String(ev) => ev, | |
_ => "message", | |
}) | |
.unwrap_or("message") | |
.into(), | |
.map(|value| match value { | |
Value::String(ev) => Event::from(ev), | |
_ => Event::Message, | |
}) | |
.unwrap_or(Event::Message), |
Hey, FWIW, I tried out the async version and everything seemed to work except for event callbacks (not sure how comprehensively those are tested). The sync version of the library works fine with the same calling code, so I'm pretty sure it was not a server config problem. |
@JackFlukinger I found the callback not |
hi, @1c3t3a :
For reconnecting, the Client is cloneable, and the real client is
|
Another option is rather than sending the client in the callback, send an intermediary object that can uses a message channel (or similar means) to send messages out over the client. Inside the callback you don't really need to have the full powers of the client, just send messages/close connection/etc. |
35ac8b3
to
e8032e6
Compare
Thanks for the valuable discussion in this PR! I am going to merge this PR now, it comes with fairly good documentation of the new async part and I hope to get some feedback on the async API eventually (especially regarding the valuable points here raised by @SSebo and @nshaaban-cPacket). I am releasing this as an |
This PR builds upon the async engine.io version and adds an async socket.io interface.
The interface is similar to the sync one and provides most methods in an async fashion. Note that the async version can currently only be used with
tokio
.An Issue I stumbled upon while writing this, is the verbose way of defining callbacks (they need to return boxed futures).
I explained the issue here. From my point of view there is currently no better way than using
async { .. }.boxed()
.