
On Mon, Dec 30, 2024 at 2:04 AM Richard Hodges via Boost < boost@lists.boost.org> wrote:
If you want to run composed operations sequentially (with respect to each other) then you must coordinate this yourself via an “asynchronous mutex or semaphore”.
Asio’s timer object can be used as a semaphore : - set to max timeout - use cancel_one() to release the next job.
Asio seems to have thread-safe channels in its experimental namespace, these would work as well. To Richard's point, you're usually better off reaching for the channel abstraction here because it actually does what you want, just more straightforwardly. Something like this: https://godbolt.org/z/8zxTPsbG4 You can emulate this using the techniques Richard alluded to as well. You can use a timer like a condition variable and have your loop asynchronously block on it via `.async_wait()` with the maximum timeout. Wakeups happen by cancellation, which you'd ignore in your processing loop. This enables you to trivially handle the case where processing work items is an inherently asynchronous task composed of multiple I/O ops. - Christian