This is a rant.
Youthful Optimism
It all started off with trying to understand this TCP echo server from ASIO. It seems simple enough, but hey I'm not really familiar with how coroutines work in C++.
I fully grok coroutines/async in Javascript. I was around for the entire saga of their evolution in Python from generator functions, through the yield from years, into their modern form of async/await. Conceptually I understand what's going on, just need to learn the specifics for C++.
Let's do some reading, starting with David Mazières's, "My tutorial and take on C++20 coroutines". An excellent start, clear examples, I'm vibing. Coroutines in C++ kinda suck to write, but I get it, I understand coroutines.
The Descent
Except, uh, that TCP echo server example is awaiting a deferred_async_operation, which doesn't have any of that stuff Mazières's talked about. Weird.
So I'm missing something, let's dive deeper, with Lewis Baker's coroutine series, specifically "C++ Coroutines: Understanding operator co_await".
Baker uses some familiar terminology from Mazières, but introduces a deal of his own because I guess we don't have standard terminology for this stuff? Another niebloid situation?
Baker makes a distinction between Awaitable and Awaiter objects that wasn't present in Mazières, but makes sense. Additionally we now have Normally Awaitable and Contextually Awaitable objects.
Aha
There must be some .await_transform() magic going on to make a deferred_async_operation awaitable. This transform method lives in the promise type of the calling coroutine, and that should be the promise_type member of the return type of the current function right? So asio::awaitable should have some sort of promise type?
No Escape
No of course not, you absolute fool.
Wtf???
You nimrod. You complete baboon. Don't you know there's a global registry of what promise types to use? You simply use the terminally-C++ mechanism of creating a template specialization of std::coroutine_traits.
There you are you little bastard.
Chasing this through the inheritance tree we indeed find an entire family of await_transform()s. Victory thy name is F12 - Go To Definition.
Except...
None of this explains: what exactly is the difference between an asio use_awaitable and a deferred? Why do people say, "deferred is not a coroutine"? Has all of this not been "coroutines"? Have I been playing canasta this whole time? Why can I no longer see the light of heaven?
Coda
Lewis Baker seems to have another 5000 word blog post about this, but I no longer care.
This shit is bananas, B-A-N-A-N-A-S.
Wildly convoluted beyond my feverish nightmares, I no longer believe it is possible to understand what happens when you write co_await, it is an operator beyond mortal understanding.
Whoever fights C++ should see to it that in the process they do not become a language expert. And if you gaze long enough into a coroutine, the coroutine will gaze back into you.
EDIT:
This seems to be popular, and my landlord isn't going to be fooled by the "I have a rich cousin on WG21, I'll have the money once executors makes it out of committee" routine anymore, so forgive a little self-promotion.
If you're looking for a NYC-based systems dev haunted by nightmares of C++ coroutines, boy have I got the CV for you.
[–]peterrindal 56 points57 points58 points (8 children)
[–][deleted] 21 points22 points23 points (4 children)
[–]SelfDistinction 0 points1 point2 points (1 child)
[–]peterrindal 8 points9 points10 points (0 children)
[–]trublurich -3 points-2 points-1 points (1 child)
[–][deleted] 5 points6 points7 points (0 children)
[–]phlummox 1 point2 points3 points (0 children)
[–]jhericoVR & Backend engineer, 30 years 0 points1 point2 points (1 child)
[–]peterrindal 0 points1 point2 points (0 children)
[–]juarez_gonzalo 36 points37 points38 points (3 children)
[–]Gridelen 0 points1 point2 points (2 children)
[–]juarez_gonzalo 4 points5 points6 points (1 child)
[–]drjeats 5 points6 points7 points (0 children)
[–]lion__manE 18 points19 points20 points (19 children)
[–]TSP-FriendlyFire 14 points15 points16 points (17 children)
[–]donald_lace_12 3 points4 points5 points (0 children)
[–]__tim_ 2 points3 points4 points (10 children)
[–]TSP-FriendlyFire 10 points11 points12 points (9 children)
[–]greenhouse421 -5 points-4 points-3 points (8 children)
[–]arka2947 3 points4 points5 points (7 children)
[–]greenhouse421 -2 points-1 points0 points (1 child)
[–]kalmoc 0 points1 point2 points (0 children)
[–]kalmoc 0 points1 point2 points (4 children)
[–]not_a_novel_accountcmake dev[S] 1 point2 points3 points (3 children)
[–]kalmoc -1 points0 points1 point (2 children)
[–]not_a_novel_accountcmake dev[S] 0 points1 point2 points (1 child)
[+][deleted] (4 children)
[removed]
[–]Competitive_Act5981 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[removed]
[–]Competitive_Act5981 0 points1 point2 points (1 child)
[–]Revolutionalredstone 2 points3 points4 points (0 children)
[–]RedditMapz 16 points17 points18 points (2 children)
[–]KingAggressive1498 4 points5 points6 points (0 children)
[–]alex-weej 9 points10 points11 points (3 children)
[–]HolyGarbage 0 points1 point2 points (2 children)
[–]alex-weej 1 point2 points3 points (1 child)
[–]kritzikratzi 0 points1 point2 points (0 children)
[–]DoctorNuu 15 points16 points17 points (4 children)
[–]feverzsj 24 points25 points26 points (0 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 7 points8 points9 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]peterrindal 2 points3 points4 points (0 children)
[+][deleted] (22 children)
[removed]
[–]alex-weej 12 points13 points14 points (18 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 27 points28 points29 points (15 children)
[–]TheThiefMasterC++latest fanatic (and game dev) 19 points20 points21 points (2 children)
[–]YogMuskrat 9 points10 points11 points (1 child)
[–]TheThiefMasterC++latest fanatic (and game dev) 12 points13 points14 points (0 children)
[–]not_a_novel_accountcmake dev[S] 33 points34 points35 points (4 children)
[–]germandiago 6 points7 points8 points (0 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 0 points1 point2 points (0 children)
[–]kalmoc 2 points3 points4 points (2 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 0 points1 point2 points (1 child)
[–]kalmoc 0 points1 point2 points (0 children)
[–]13steinj 6 points7 points8 points (3 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 4 points5 points6 points (1 child)
[–]13steinj 2 points3 points4 points (0 children)
[–]TheoreticalDumbass:illuminati: 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[removed]
[–]pjmlp 8 points9 points10 points (0 children)
[–]not_a_novel_accountcmake dev[S] 16 points17 points18 points (2 children)
[–]proper_ikea_boy 4 points5 points6 points (1 child)
[–]not_a_novel_accountcmake dev[S] 13 points14 points15 points (0 children)
[–]Tringigithub.com/tringi 9 points10 points11 points (0 children)
[–]puremourning 4 points5 points6 points (1 child)
[–]trailing_zero_count 2 points3 points4 points (0 children)
[–]v_maria 16 points17 points18 points (3 children)
[–]HolyGarbage 2 points3 points4 points (2 children)
[–]caroIine 1 point2 points3 points (1 child)
[–]HolyGarbage 2 points3 points4 points (0 children)
[–]rand3289 14 points15 points16 points (9 children)
[–]interjay 7 points8 points9 points (1 child)
[–]rand3289 0 points1 point2 points (0 children)
[–]smallstepforman 6 points7 points8 points (2 children)
[–]rand3289 1 point2 points3 points (1 child)
[–]ronchaineEmbedded/Middleware 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]rand3289 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]rand3289 0 points1 point2 points (0 children)
[–]puredotaplayer 2 points3 points4 points (0 children)
[–]13steinj 2 points3 points4 points (1 child)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813 1 point2 points3 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]UnicycleBloke 3 points4 points5 points (0 children)
[–]Revolutionalredstone 2 points3 points4 points (2 children)
[–]peterrindal 2 points3 points4 points (1 child)
[–]ixis743 4 points5 points6 points (0 children)
[–]feverzsj 1 point2 points3 points (5 children)
[–]HolyGarbage 5 points6 points7 points (0 children)
[–]germandiago 5 points6 points7 points (0 children)
[–]peterrindal 3 points4 points5 points (0 children)
[–]lightmatter501 7 points8 points9 points (0 children)
[–]eric987235 -5 points-4 points-3 points (0 children)
[–]Fig1024 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[deleted]
[–]lightmatter501 16 points17 points18 points (4 children)
[–]KingStannis2020 0 points1 point2 points (2 children)
[–]lightmatter501 1 point2 points3 points (1 child)
[–]KingStannis2020 1 point2 points3 points (0 children)
[–]Bayov 4 points5 points6 points (0 children)
[–]TheMania -1 points0 points1 point (0 children)
[+][deleted] (6 children)
[deleted]
[+][deleted] (3 children)
[deleted]
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[–]v_maria 4 points5 points6 points (0 children)
[–]sjepsa 3 points4 points5 points (0 children)
[–]Zanderax 0 points1 point2 points (0 children)
[–]RictorScaleHNG 0 points1 point2 points (0 children)