TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What are senders good for, anyway?

27 pointsby davikrover 1 year ago

4 comments

userbinatorover 1 year ago
After reading all that, my only thought is: &quot;Now let&#x27;s see you debug that.&quot;<p>IMHO the more abstract and complex a system is, the more chances that something will go wrong. When one has to figure out what&#x27;s actually happening among a huge mess of overly-abstracted code, simple and straightforward always wins. Perhaps it&#x27;s some kind of job security.
评论 #39275476 未加载
LastTrainover 1 year ago
I always kind of scratch my head at this kind of language extension. In my world there are legacy projects and new projects. Why would I want introduce this into a legacy codebase? If it’s a new project where async language features are important, why wouldn’t I use a language better suited for that?
评论 #39275911 未加载
评论 #39286303 未加载
vintagedaveover 1 year ago
When reading the blog, I saw these really long, complex bits of code and was thinking to myself, &quot;_this_ is simpler?!&quot;<p>It turns out those long complex pieces of code are not something the consumer, the program writer, me and you, will ever need to see. If the author reads this, I apologise for saying so, but IMO the blog post aims well but misfires: it needs to communicate to C++ developers what code _they_, ie _us_ normal folk, will see and write. Otherwise we&#x27;ll get scared off. (But, I do note your absolute enthusiasm shines through and that carried me through the entire post :))<p>&gt; At this point you may be wondering what’s the point to all of this. Senders and receivers, operation states with fiddly lifetime requirements, connect, start, three different callbacks — who wants to manage all of this? The C API was way simpler. It’s true! So why am I so unreasonably excited about all of this? The caller of async_read_file doesn’t need to care about any of that.<p>This is in &quot;step 6&quot;, about ten screens into the blogpost. Good thing I read the whole thing!<p>So, THIS is the takeaway. You have old code (C-style, like the Win32 API):<p><pre><code> &#x2F;&#x2F;&#x2F; Old-style async C API with a callback &#x2F;&#x2F;&#x2F; (like Win32&#x27;s ReadFileEx) struct overlapped { &#x2F;&#x2F; ...OS internals here... }; using overlapped_callback = void(int status, int bytes, overlapped* user); int read_file(FILE*, char* buffer, int bytes, overlapped* user, overlapped_callback* cb); </code></pre> and this transforms into new C++ code:<p><pre><code> exec::task&lt; std::string &gt; process_file( FILE* pfile ) { std::string str; str.resize( MAX_BUFFER ); auto [bytes, buff] = co_await async_read_file(pfile, str.data(), str.size()); str.resize( bytes ); co_return str; } </code></pre> Plus the additional money quote:<p>&gt; You want to use senders because then you can stitch your async operations together with other operations from other libraries using generic algorithms from still other libraries. And so you can co_await your async operations in coroutines without having to write an additional line of code.<p>&gt; Why do we need senders when C++ has coroutines? [...] this isn’t an either&#x2F;or. Senders are part of the coroutine story.<p>And actually -- that looks pretty good to me!<p>And if the author reads this, if I may suggest, put this first! (Combined with the note about multiple different APIs all made cohesive, give two examples perhaps.) But sell the solution, then explain the intricate mechanism.<p>And, great work. I can see myself writing code using this. I like it.
secondcomingover 1 year ago
It&#x27;s not like C++ devs have much choice but to deal with this stuff since Asio was effectively kicked out of standardisation.<p>Asio also has its flaws, but the async story in C++ has quite the cognitive overload.
评论 #39279202 未加载