This question nerd-sniped me by a problem mentioned in the comments:
@sehe
use_promiseseems very interesting. I looked up some documentation about it and found some of your posts, like this. But how could I imitateboost::wait_for_allwithuse_promise? There seems to be also a problem to have two tasks waiting for one single task to finish. – YzEdwin Commented yesterdayYou can make a group of async operations (
make_parallel_group) and then initiate it withuse_promise. Incidentally,experimental::promiseis especially versatile because the promise'soperator()makes that an async operation as well, so it can be grouped/deferred in turn – sehe Commented yesterday@sehe I finally got
use_promiseworking withmake_parallel_group. I was usingasio::deferredbefore. I guessuse_promiseis more like eager evaluation? But still the biggest problem is forking. E.g. I have two independent tasks A and B, which are both relying on task C to finish. All three events should be executed only once. This could easily be done withboost::shared_futureas I could just pass theshared_futureof task C to thethen()of task A and B. But if I useco_spawnand both tasksco_awaittask C, task C will be executed twice. – YzEdwin Commented 20 hours ago
The shared-dependency point is valid: asio::experimental::promise<...> is move-only and cannot be awaited twice. In that respect it's more like wrapped async operation (as per the concept check is_async_operation).
Can we wrap the promise into a copyable/shared promise type?
How would we do that?
Is the
experimental::promiseeven required?