|
Boost : |
Subject: Re: [boost] [next gen future-promise] Whattocallthemonadicreturntype?
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2015-05-26 11:43:41
On 26 May 2015 3:54 pm, "Peter Dimov" <lists_at_[hidden]> 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<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; }.)
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk