Boost logo

Boost :

Subject: Re: [boost] Futures - wait callback with a user specific parameter.
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-01-15 15:29:18


----- Original Message -----
From: "vicente.botet" <vicente.botet_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, January 15, 2009 6:47 PM
Subject: Re: [boost] Futures - wait callback with a user specific parameter.

>
> Hi,
>
> Currently the wait callback parameter is either a promise or packaged_task
> template<typename F>
> void set_wait_callback(F f);
>
> prom.set_wait_callback(f); // will call f(&prom)
> task.set_wait_callback(f); // will call f(&task)
>
> I would like to have a wait callback with a user specific parameter.
> template<typename F,typename U>
> void set_wait_callback(F f,U* u); // will call f(u)
>
> prom.set_wait_callback(f, x); // will call f(x)
>
> The use case is a class that contains a promise and wants to provide a set_wait_callback. Which parameter will have the wait calback? A promise. But the user is not aware that my class has promise, and he will surely want to have as parameter a pointer to my class. So the simpler is to provide a user specific parameter that is defaulted to instance providing the wait_callback setting.
>
> Of course my class can wrap the user function and the class instance
>
> template <typename R>
> class X {
> template <typename F>
> static void wait_callback_wrapper(promise<R>* p, F f, X*x) {
> f(x);
> }
>
> template<typename F>
> void set_wait_callback(F f) {
> prom_.set_wait_callback(bind(wait_callback_wrapper, _1, f, this));
> }
> };
>
> But this implies much more resources, two binds instead of one.
> Could this be added without to much trouble?

Anthony, I've find this on one your posts:
>> At the moment, I've specified the callbacks as taking a
>> non-const reference to the promise or packaged_task for which they are set,
>> but I'm open to just making them be any callable function, and leaving it up
>> to the user to call bind() to do that.

Anthony, I think that just a callable function will be the best option.

Vicente


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