-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Enhancement] Migrate to coroutines in the interface #74
Comments
As discussed previously: I am all pro using coroutines - but unfortunately not unless MinGW-w64 & GCC shipped by MSYS2 can compile |
I wanted to add this mental note ever since I read the changelog of boost v1.77.0: There are changes to coroutines. Might be worth exploring. |
clang 13 is now out (and in the arch repo) so I may start looking at migrating to corountines. Problem is this is going to break all existing code, and in ways that are not just a search and replace fix either (existing code must also use coroutines or wrap stuff up in asio spawns). Ideally we'd instead migrate to the |
Awesome to hear from you again! :) I really don't know what to tell you... this is a difficult situation... A couple of months ago I did investigate the boost ASIO stuff but I trailed off mainly due to lack of documentation and then side-tracked into an endless pit of interesting stuff - as one does when looking at
Could you elaborate as to why you'd think this is the ideal choice? |
It would allow the user to pick what kind of async interface they wanted (so they could even write their own or use their existing custom one they wrote for asio with this). The immediate advantage in terms of coroutine migration is it would allow I agree though that it might be better to just support coroutines, all the guides and such on implementing the api require a lot of boilerplate e.g. (a new struct with a bunch of Another thing to consider is I thiiink the CompletionToken api is part of the networking ts. Personally I think I'm going to at least try converting one or two paths of the websocket interface, and see how messy/possible it is (unless you have any major objections of course) |
Of course I don't! I am very thankful for this. As mentioned I did look into it myself and came to similar conclusion as you stated. I think even if we can pull it of (which I don't doubt) it's gonna be a b*tch to maintain. Another upside of just using straight coroutines would be that Then there is that other benefit as you mentioned:
|
Alright, so I've managed to get
Edit: |
Okay so I have it working with
Then just invoke the final handler when done. Having said that, it does seem to have made my compile times go up to minutes for My vote is that we switch to this at least for all the client stuff, my only concern is the compile times for just the tests have already skyrocketed (at least for me), I think this is actually the coroutines and not the templates (clang, for which the coroutine tests are ifdef'd out, compiles at normal speed). Thoughts? |
Nice work! I can have a much closer look at this on the 2nd of January. Unfortunately I could only glance over your work so far. I'm really not sure whether it's worth migrating to the "new" After your experiments, do you think it's worth pursuing this (leaving compile-times out of the discussion for now)? |
Yes. It will allow supporting all current environments + using the cool new stuff as and when it becomes available with no extra code changes from us. I've now migrated all of Adding support for this only needs a few lines of code in most cases. I did run into a slight issue with the action queues in
Compile times seem to be a problem only when actually using the coroutines, I'm not sure if its because of complex TMP needed to make them work or gcc's coroutine implementation being a bit slow right now or a bit of both, but the bottom line is if you don't use it you don't pay for it (as far as I can tell). Although I agree that generally I've implemented this now for send, read, accept, and connect for websocket connection. Also I've managed to make gcc crash when trying to compile the coroutine tests, which I consider something of an achievement.
True, but there are cases for this beyond just allowing easier migration to coroutines. The CompletionToken api allows very deep customization of how the control flow is returned to the caller, including error handling which is something I've been eyeing for #40 for some time. I think the only real sticking point is still
I'm on the fence between 1 and 4 honestly. But I'm leaning more toward 1 as it is kinda surprising behavior if you change away from your lambda and suddenly need |
I see this not as a major - but reasonably important plus.
I didn't consider that - you're absolutely right. #40 is quite a biggie on my side as well (and probably for anybody who wants to use
I see what you mean... I truly do... I appreciate your efforts on this front. I think this will be a good step forward and certainly future-proofing. On that note: We'll most likely get a |
Taken from my comment here: #70. For tracking and discussion
Moving everything to coroutines might be quite the job. Mostly thinking of the problems mentioned in #40. Also we might have to roll a few of our own coroutines as
asio
is rather lacking there (awaitable
seems to be it, so no tasks or generators).I'm personally leaning more toward having coroutines (in the interface) in the release after
0.1
as a major API change since I think theres a few parts which could be improved with coroutines (e.g.client::controller::ws_connect
could return a connection again, and server handlers could optionally be coroutines).Parts of the API that might benefit from coroutines, off the top of my head
client::controller::ws_connect
: Could return an awaitable to the connection objectco_await
in the bodies of themsend, accept, read, etc
inwebsocket::connection
: These currently use callbacks, making them coroutines could not only clean things up a little but also make [Bug] websocket::connection::read does not interleave with websocket::connection::send #70 simplerclient::controller::http_connect
currently uses a callback with a response. Since we have the Filter type we can use a templated coroutine return. This does however sacrifice the implicit visitorness of the callback, so that one needs a bit more thoughtfuture
The text was updated successfully, but these errors were encountered: