Writing Senders -- Lucian Radu Teodorescu
Senders/receivers can be used to introduce concurrency. Lucian Radu Teodorescu describes how to implement senders.
Writing Senders
by Lucian Radu Teodorescu
From the article:
If people are just using frameworks based on
std::execution, they mainly need to care about senders and schedulers. These are user-facing concepts. However, if people want to implement sender-ready abstractions, they also need to consider receivers and operation states – these are implementer-side concepts. As this article mainly focuses on the implementation of sender abstractions, we need to discuss these two concepts in more detail.A receiver is defined in P2300 as “a callback that supports more than one channel” [P2300R10]. The proposal defines a concept for a receiver, unsurprisingly called
receiver. To model this concept, a type needs to meet the following conditions:
- It must be movable and copyable.
- It must have an inner type alias named
receiver_conceptthat is equal toreceiver_t(or a derived type).std::execution::get_env()must be callable on an object of this type (to retrieve the environment of the receiver).A receiver is the object that receives the sender’s completion signal, i.e., one of
set_value(),set_error(), orset_stopped(). As explained in the December 2024 issue [Teodorescu24], a sender may have different value completion types and different error completion types. For example, the same sender might sometimes complete withset_value(int, int), sometimes withset_value(double), sometimes withset_error(std::exception_ptr), sometimes withset_error(std::error_code), and sometimes withset_stopped(). This implies that a receiver must also be able to accept multiple types of completion signals.

Registration is now open for CppCon 2025! The conference starts on September 15 and will be held
In today's post I share a learning of a customer with you. A while back, a customer asked me to join a debugging session. They had an issue they didn't (fully) understand.
Registration is now open for CppCon 2025! The conference starts on September 15 and will be held
A unique milestone: “Whole new language”
Registration is now open for CppCon 2025! The conference starts on September 15 and will be held
Templates are one of C++’s most powerful features, enabling developers to write generic, reusable code—but they come with a cost: notoriously verbose and opaque error messages. With the introduction of concepts in C++20, we can now impose clear constraints on template parameters and get far more helpful diagnostics when something goes wrong.