3 ms·
Do coroutines help with the need for sharing state with timers? When you make a async operation there are two things: the operation itself, e.g. read/write and
by secondcoming 6y ago
Do coroutines help with the need for sharing state with timers?
When you make a async operation there are two things: the operation itself, e.g. read/write and the timer associated with that operation (you really don't want infinite timeouts in production code).
Both need information about the async operation in their respective handlers. You can't do composed operations (std::move(this)) since one of the read/write or timer handlers will be given a moved-from object.
The only wasy I can see to solve this is through the use of a ringbuffer and using indexes into this ringbuffer as a 'handle' to the async op (see LMAX's Disruptor). It saves from needing shared_ptr / enable_shared_from_this. You're going to need a bounded queue anyway to prevent a fast producer from causing OOM.