
26 May
2015
26 May
'15
2:53 p.m.
Giovanni Piero Deretta wrote:
Can it be generic? Do you have a generic implementation of when_any?
You do need to standardise a generic asynchronous wait protocol of course.
Or, I can make promises shared as well, and then use .then. when_any( f1, f2, f3 ) { future<size_t> f; promise<size_t> p(f); f1.then( [p](auto){ p.set_value(0); } ); f2.then( [p](auto){ p.set_value(1); } ); f3.then( [p](auto){ p.set_value(2); } ); return f.then( []( future<size_t> index ) { return make_pair(index.get(), make_tuple(f1, f2, f3)); }); } Something like that. (I still don't need a mutex for the multiple set_value calls, by the way - if(rn_++ == 0) { set the value; publish/notify; }.)