Boost logo

Boost :

Subject: Re: [boost] [next gen future-promise] Whattocallthemonadicreturntype?
From: Peter Dimov (lists_at_[hidden])
Date: 2015-05-26 10:53:37


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; }.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk