Commit a3e9ca8
asioexec::completion_token & ::use_sender
Adds two completion tokens for interop with Asio (either Boost.Asio or
standalone Asio).
asioexec::completion_token performs the most basic transformations
necessary to transform an Asio initiating function into a sender
factory:
- The initiating function returns a sender
- Initiation is deferred until the above-mentioned sender is connected
and the resulting operation state is started
- The completion handler provided to the initiation (see asio::
async_initiate) has the following properties:
- Invocation results in the arguments thereto being sent via a value
completion signal (this means that errors transmitted via a leading
error_code parameter (i.e. in Asio style) are delivered via the
value channel, see below)
- Abandonment thereof (i.e. allowing the lifetime of the completion
handler, and all objects transitively derived by moving therefrom,
to end without invoking any of them) results in a stopped completion
signal
- Any exception thrown from any intermediate completion handler, or
the final completion handler, is sent via an error completion signal
with a std::exception_ptr representing that exception (this is
accomplished by wrapping the associated executor)
- The cancellation slot is connected to a cancellation signal which
is sent when a stop request is received via the receiver's
associated stop token
The fact that invocations of the completion handler are passed to the
value channel untouched reflects the design intent that the above-
described completion token perform only "the most basic transformations
necessary." This means that the full context of partial success must be
made available and since the error channel is unary this must be
transmitted in the value channel.
For a more ergonomic experience than that described above asioexec::
use_sender is also provided. This uses asioexec::completion_token to
adapt an Asio initiating function into a sender factory and wraps the
returned sender with an additional layer which performs the following
transformations to value completion signals with a leading error_code
parameter (note that when configured for standalone Asio std::error_code
is matched whereas when configured for Boost.Asio both boost::system::
error_code and std::error_code are matched):
- If that argument compares equal to errc::operation_cancelled
transforms the value completion signal into a stopped completion
signal, otherwise
- If that argument is truthy transforms the value completion signal into
an error completion signal with an appropriate std::exception_ptr
(i.e. one which points to a std::system_error for std::error_code,
boost::system::system_error for boost::system::error_code), otherwise
- Sends the remainder of the arguments (i.e. all but the error_code) as
a value completion signal1 parent aacec6f commit a3e9ca8
9 files changed
Lines changed: 1798 additions & 0 deletions
File tree
- include/asioexec
- test
- asioexec
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
436 | 443 | | |
437 | 444 | | |
438 | 445 | | |
| |||
449 | 456 | | |
450 | 457 | | |
451 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
452 | 469 | | |
453 | 470 | | |
454 | 471 | | |
| |||
464 | 481 | | |
465 | 482 | | |
466 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
467 | 494 | | |
468 | 495 | | |
469 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments