mirror of
https://github.com/capnproto/pycapnp.git
synced 2025-03-04 00:14:45 +01:00
No more need for promise joining
This commit is contained in:
parent
20868d7db0
commit
da6a07efd5
2 changed files with 7 additions and 27 deletions
|
@ -58,32 +58,25 @@ void check_py_error() {
|
|||
}
|
||||
}
|
||||
|
||||
inline kj::Promise<kj::Own<PyRefCounter>> maybeUnwrapPromise(PyObject * result) {
|
||||
check_py_error();
|
||||
auto promise = extract_promise(result);
|
||||
Py_DECREF(result);
|
||||
return kj::mv(*promise);
|
||||
}
|
||||
|
||||
kj::Promise<kj::Own<PyRefCounter>> wrapPyFunc(kj::Own<PyRefCounter> func, kj::Own<PyRefCounter> arg) {
|
||||
GILAcquire gil;
|
||||
// Creates an owned reference, which will be destroyed in maybeUnwrapPromise
|
||||
PyObject * result = PyObject_CallFunctionObjArgs(func->obj, arg->obj, NULL);
|
||||
return maybeUnwrapPromise(result);
|
||||
check_py_error();
|
||||
return stealPyRef(result);
|
||||
}
|
||||
|
||||
kj::Promise<kj::Own<PyRefCounter>> wrapPyFuncNoArg(kj::Own<PyRefCounter> func) {
|
||||
GILAcquire gil;
|
||||
// Creates an owned reference, which will be destroyed in maybeUnwrapPromise
|
||||
PyObject * result = PyObject_CallFunctionObjArgs(func->obj, NULL);
|
||||
return maybeUnwrapPromise(result);
|
||||
check_py_error();
|
||||
return stealPyRef(result);
|
||||
}
|
||||
|
||||
kj::Promise<kj::Own<PyRefCounter>> wrapRemoteCall(kj::Own<PyRefCounter> func, capnp::Response<capnp::DynamicStruct> & arg) {
|
||||
GILAcquire gil;
|
||||
// Creates an owned reference, which will be destroyed in maybeUnwrapPromise
|
||||
PyObject * ret = wrap_remote_call(func->obj, arg);
|
||||
return maybeUnwrapPromise(ret);
|
||||
PyObject * result = wrap_remote_call(func->obj, arg);
|
||||
check_py_error();
|
||||
return stealPyRef(result);
|
||||
}
|
||||
|
||||
::kj::Promise<kj::Own<PyRefCounter>> then(kj::Own<kj::Promise<kj::Own<PyRefCounter>>> promise,
|
||||
|
|
|
@ -155,19 +155,6 @@ cdef api VoidPromise * call_server_method(object server,
|
|||
.format(method_name, str(ret)))
|
||||
|
||||
|
||||
cdef api Own[Promise[Own[PyRefCounter]]] extract_promise(object obj):
|
||||
if type(obj) is _Promise:
|
||||
return move((<_Promise>obj).thisptr)
|
||||
elif type(obj) is _RemotePromise:
|
||||
parent = (<_RemotePromise>obj)._parent
|
||||
# We don't need parent anymore. Setting to none allows quicker garbage collection
|
||||
(<_RemotePromise>obj)._parent = None
|
||||
return capnp.heap[PyPromise](helpers.convert_to_pypromise(move((<_RemotePromise>obj).thisptr))
|
||||
.attach(capnp.heap[PyRefCounter](<PyObject *>parent)))
|
||||
else:
|
||||
return capnp.heap[PyPromise](capnp.heap[PyRefCounter](<PyObject *>obj))
|
||||
|
||||
|
||||
cdef extern from "<kj/string.h>" namespace " ::kj":
|
||||
String strStructReader" ::kj::str"(C_DynamicStruct.Reader)
|
||||
String strStructBuilder" ::kj::str"(DynamicStruct_Builder)
|
||||
|
|
Loading…
Add table
Reference in a new issue