r/cpp • u/DmitryiKh • Feb 11 '21
`co_lib` - experimental asynchronous C++20 framework that feels like std library
Inspired the way how boost::fibers and Rust's async-std mimic standard library but in asynchronous way, I try to write c++20 coroutines framework that reuse std library concurrency abstractions but with co_await.
It's mostly experimental and on early stage. But I would like to share with you some results.
The library itself: https://github.com/dmitryikh/co_lib (proceed with examples/introduction.cpp to get familiar with it). Here is an attempt to build redis async client based on `co_lib`: https://github.com/dmitryikh/co_redis
My ultimate goal is to build `co_http` and then `co_grpc` implementations from scratch and try to push it to production.
20
Upvotes
4
u/DmitryiKh Feb 12 '21
Thanks for the valuable comments!
My opinion is that channel is an extension of promise/future idea, but can send more than one value. Usually channels are used to communicate between threads. That means that a lifetime of a channel is not obviously determined. Thus it's better to have reference counting for the state inside to avoid misuse (dangling references).
I'll fix error_category error
I have worries about boost dependency too. Currently I use not so much: intrusive list, circular buffer, outcome. I'm trying to not invent the wheel and use battle tested pieces of code.
I'm trying to avoid building another swiss knife library where all moving parts can be replaced. So I would stick with `libuv` as a event loop and polling backend.
about co::invoke. Thanks, I will have a look on it.
`when_any`. I don't like the idea that we run some tasks, detach them and forget about it. It's a way to have dangling reference problems. Thats why I've been started to experiment with explicit cancellation of unused tasks. Of course, there should be "fire and forget" version of when_any, as you proposed.