You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by 易剑 <ey...@gmail.com> on 2015/04/15 05:32:34 UTC
Why thrift not add Closure for async call?
// specified for 0 argument
template <typename R>
class Closure<R> : public ClosureBase
{
public:
virtual R Run() = 0;
};
// specified for 1 argument
template <typename R, typename Arg1>
class Closure<R, Arg1> : public ClosureBase
{
public:
virtual R Run(Arg1 arg1) = 0;
};
// specified for 2 arguments
template <typename R, typename Arg1, typename Arg2>
class Closure<R, Arg1, Arg2> : public ClosureBase
{
public:
virtual R Run(Arg1 arg1, Arg2 arg2) = 0;
};
template <
bool SelfDeleting,
typename R,
typename Class, typename MethodClass
>
class MethodClosure_Arg0_Bind0 : public Closure<R> {
typedef R (MethodClass::*MethodType)();
public:
MethodClosure_Arg0_Bind0(Class *object, MethodType method):
m_object(object), m_method(method) {}
virtual ~MethodClosure_Arg0_Bind0() {
m_object = 0;
m_method = 0;
}
virtual R Run() {
ConditionalAutoDeleter<SelfDeleting, MethodClosure_Arg0_Bind0>
self_deleter(this);
return (m_object->*m_method)();
}
virtual bool IsSelfDelete() const { return SelfDeleting; }
private:
Class* m_object;
MethodType m_method;
};
template <
bool SelfDeleting,
typename R,
typename Arg1,
typename Arg2,
typename Arg3,
typename PreArg1
>
class FunctionClosure_Arg2_Bind1 : public Closure<R, Arg2, Arg3> {
typedef R (*FunctionType)(Arg1, Arg2, Arg3);
public:
FunctionClosure_Arg2_Bind1(FunctionType function, PreArg1 pa1):
m_function(function), m_pa1(pa1) {}
virtual ~FunctionClosure_Arg2_Bind1() {
m_function = 0;
}
virtual R Run(Arg2 arg2, Arg3 arg3) {
ConditionalAutoDeleter<SelfDeleting, FunctionClosure_Arg2_Bind1>
self_deleter(this);
return m_function(m_pa1, arg2, arg3);
}
virtual bool IsSelfDelete() const { return SelfDeleting; }
private:
FunctionType m_function;
PreArg1 m_pa1;
};