Open
Description
I wanted to implement the server side of a capnproto schema that has a method that returns 2 values. The first value is a capability that can be used to send some data, and the second value is a promise of something that depends on this received data.
Is this possible to do with this library?
Example schema:
interface EventDispatcher {
dispatch @0 (metadata :Metadata) -> (data :ByteStream, response :Response);
}
interface ByteStream {
write @0 (bytes :Data) -> stream;
end @1 ();
}
I've tried using a PromiseFulfillerPair
but if I return this no progress is made, and the rpc just stalls:
class ByteStreamImpl(example_capnp.ByteStream.Server):
def __init__(self, promise):
super().__init__()
self.data = b''
self.promise = promise
def write(self, bytes, _context, **kwargs):
self.data += bytes
return None
def end(self, _context, **kwargs):
self.promise.fulfill()
class DispatcherImpl(example_capnp.EventDispatcher.Server):
def dispatch(self, metadata, _context, **kwargs):
p = capnp.PromiseFulfillerPair()
bstream = ByteStreamImpl(p)
def set_result(_res):
response = example_capnp.Response()
response.outcome = len(bstream.data)
_context.results.response = response
_context.results.data = bstream
return p.promise.then(set_result)
Am I doing something wrong or is this just not possible?
Thanks.
Metadata
Metadata
Assignees
Labels
No labels