Add then function for VoidPromise
This commit is contained in:
@@ -70,6 +70,14 @@ PyObject * wrapPyFunc(PyObject * func, PyObject * arg) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject * wrapPyFuncNoArg(PyObject * func) {
|
||||||
|
PyObject * result = PyObject_CallFunctionObjArgs(func, NULL);
|
||||||
|
Py_DECREF(func);
|
||||||
|
|
||||||
|
check_py_error();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void wrapRemoteCall(PyObject * func, capnp::Response<capnp::DynamicStruct> & arg) {
|
void wrapRemoteCall(PyObject * func, capnp::Response<capnp::DynamicStruct> & arg) {
|
||||||
wrap_remote_call(func, arg);
|
wrap_remote_call(func, arg);
|
||||||
|
|
||||||
@@ -92,6 +100,14 @@ void wrapRemoteCall(PyObject * func, capnp::Response<capnp::DynamicStruct> & arg
|
|||||||
, [error_func](kj::Exception arg) { wrapPyFunc(error_func, wrap_kj_exception(arg)); } );
|
, [error_func](kj::Exception arg) { wrapPyFunc(error_func, wrap_kj_exception(arg)); } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::kj::Promise<PyObject *> then(kj::Promise<void> & promise, PyObject * func, PyObject * error_func) {
|
||||||
|
if(error_func == Py_None)
|
||||||
|
return promise.then([func]() { return wrapPyFuncNoArg(func); } );
|
||||||
|
else
|
||||||
|
return promise.then([func]() { return wrapPyFuncNoArg(func); }
|
||||||
|
, [error_func](kj::Exception arg) { return wrapPyFunc(error_func, wrap_kj_exception(arg)); } );
|
||||||
|
}
|
||||||
|
|
||||||
class PythonInterfaceDynamicImpl final: public capnp::DynamicCapability::Server {
|
class PythonInterfaceDynamicImpl final: public capnp::DynamicCapability::Server {
|
||||||
public:
|
public:
|
||||||
PyObject * py_server;
|
PyObject * py_server;
|
||||||
|
|||||||
@@ -1255,7 +1255,7 @@ cdef class _Promise:
|
|||||||
if self.is_consumed:
|
if self.is_consumed:
|
||||||
raise ValueError('Promise was already used in a consuming operation. You can no longer use this Promise object')
|
raise ValueError('Promise was already used in a consuming operation. You can no longer use this Promise object')
|
||||||
|
|
||||||
ret = <object>self.thisptr.wait()
|
ret = <object>self.thisptr.wait() # TODO: make sure refcount is fine here...
|
||||||
self.is_consumed = True
|
self.is_consumed = True
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
@@ -1292,14 +1292,14 @@ cdef class _VoidPromise:
|
|||||||
self.is_consumed = True
|
self.is_consumed = True
|
||||||
|
|
||||||
|
|
||||||
# cpdef then(self, func, error_func=None) except +reraise_kj_exception:
|
cpdef then(self, func, error_func=None) except +reraise_kj_exception:
|
||||||
# if self.is_consumed:
|
if self.is_consumed:
|
||||||
# raise RuntimeError('Promise was already used in a consuming operation. You can no longer use this Promise object')
|
raise RuntimeError('Promise was already used in a consuming operation. You can no longer use this Promise object')
|
||||||
|
|
||||||
# Py_INCREF(func)
|
Py_INCREF(func)
|
||||||
# Py_INCREF(error_func)
|
Py_INCREF(error_func)
|
||||||
|
|
||||||
# return Promise()._init(capnp.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
return _Promise()._init(capnp.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
||||||
|
|
||||||
cdef class _RemotePromise:
|
cdef class _RemotePromise:
|
||||||
cdef RemotePromise * thisptr
|
cdef RemotePromise * thisptr
|
||||||
@@ -1332,7 +1332,7 @@ cdef class _RemotePromise:
|
|||||||
|
|
||||||
cpdef then(self, func, error_func=None) except +reraise_kj_exception:
|
cpdef then(self, func, error_func=None) except +reraise_kj_exception:
|
||||||
if self.is_consumed:
|
if self.is_consumed:
|
||||||
raise ValueError('Promise was already used in a consuming operation. You can no longer use this Promise object')
|
raise RuntimeError('Promise was already used in a consuming operation. You can no longer use this Promise object')
|
||||||
|
|
||||||
Py_INCREF(func)
|
Py_INCREF(func)
|
||||||
Py_INCREF(error_func)
|
Py_INCREF(error_func)
|
||||||
@@ -1361,12 +1361,6 @@ cdef class _RemotePromise:
|
|||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return list(self.schema.fieldnames)
|
return list(self.schema.fieldnames)
|
||||||
|
|
||||||
# def __str__(self):
|
|
||||||
# return printStructReader(self.thisptr).flatten().cStr()
|
|
||||||
|
|
||||||
# def __repr__(self):
|
|
||||||
# return '<%s reader %s>' % (self.schema.node.displayName, strStructReader(self.thisptr).cStr())
|
|
||||||
|
|
||||||
def to_dict(self, verbose=False):
|
def to_dict(self, verbose=False):
|
||||||
return _to_dict(self, verbose)
|
return _to_dict(self, verbose)
|
||||||
|
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ cdef extern from "capabilityHelper.h":
|
|||||||
# PyPromise there(EventLoop & loop, PyPromise & promise, PyObject * func, PyObject * error_func)
|
# PyPromise there(EventLoop & loop, PyPromise & promise, PyObject * func, PyObject * error_func)
|
||||||
PyPromise then(PyPromise & promise, PyObject * func, PyObject * error_func)
|
PyPromise then(PyPromise & promise, PyObject * func, PyObject * error_func)
|
||||||
VoidPromise then(RemotePromise & promise, PyObject * func, PyObject * error_func)
|
VoidPromise then(RemotePromise & promise, PyObject * func, PyObject * error_func)
|
||||||
|
PyPromise then(VoidPromise & promise, PyObject * func, PyObject * error_func)
|
||||||
cppclass PythonInterfaceDynamicImpl:
|
cppclass PythonInterfaceDynamicImpl:
|
||||||
PythonInterfaceDynamicImpl(PyObject *)
|
PythonInterfaceDynamicImpl(PyObject *)
|
||||||
DynamicCapability.Client new_client(InterfaceSchema&, PyObject *)
|
DynamicCapability.Client new_client(InterfaceSchema&, PyObject *)
|
||||||
|
|||||||
Reference in New Issue
Block a user