Updated specific locations to be searchable, take a look at Las Vegas as an example.

This post has been de-listed (Author was flagged for spam)

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

237
Coroutines-in-practice cannot be understood by mortals
Post Body

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.

Author
Account Strength
0%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
54,512
Link Karma
2,985
Comment Karma
44,491
Profile updated: 2 months ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
9 months ago