26 May
2015
26 May
'15
3:43 p.m.
On 26 May 2015 3:54 pm, "Peter Dimov"wrote: > > 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. > Yeah 'then' itself works fine as a wait protocol although I prefer something a bit lower level and dismissible (a 'cancel_then'). > when_any( f1, f2, f3 ) > { > future f; > promise 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 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; }.) >