Anthony Williams | 20 Jan 15:06
Picon

Re: Futures - wait callback with a user specific parameter.

"vicente.botet" <vicente.botet <at> wanadoo.fr> writes:

> From: "vicente.botet" <vicente.botet <at> wanadoo.fr>

>> 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?

It could, but....

> 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.

.... I think this is the best option.

Anthony
--

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Gmane