Re: [capnproto] Noob question: Can an interface method return null?

2022-01-12 Thread 'Kenton Varda' via Cap'n Proto
Any pointer type, including interfaces, can be null.

I think the problem here, though, is that you're making a pipelined call on
the widget before the `wigitNamed()` RPC call has actually completed, and
then later on `widgetNamed()` is completing with a null result, and so the
pipelined call fails. The error you are seeing is a little
confusingly-worded but is in fact the error that would be expected in this
scenario.

So yeah, you *are* returning null correctly, it's just that on the client
side you're trying to make a call to the null capability before the client
actually finds out that it is null.

-Kenton

On Wed, Jan 12, 2022 at 5:05 PM Jens Alfke  wrote:

> This seems like a dumb question, but I’ve been unable to find an answer. *Does
> the RPC system support null values?* In particular, if an RPC method
> returns an interface, is it able to return null?
>
> Say Widget is an interface, and in another interface I’ve got a method
> widgetNamed @1 (name: String) -> (widget: Widget);
> Can this method return null? I’m beginning to suspect it can’t, because
> when it tries to I get an error "Pipeline call on a request that returned
> no capabilities or was already closed”. (The implementation is in C++; to
> return null it just abstains from calling context.getResults().setWidget().)
>
> If it can’t, what is the idiomatic way to provide an optional return
> value? Do I return an exception, or do I create my own `Optional` type as a
> union?
>
> —Jens
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to capnproto+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/5862EBA9-F772-44A4-9736-72F70AAB0B86%40mooseyard.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to capnproto+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQnWLTYVBRgA4saKXSKOEADwo4riEnOqN8DEMSLKoheVLw%40mail.gmail.com.


[capnproto] Noob question: Can an interface method return null?

2022-01-12 Thread Jens Alfke
This seems like a dumb question, but I’ve been unable to find an answer. Does 
the RPC system support null values? In particular, if an RPC method returns an 
interface, is it able to return null?

Say Widget is an interface, and in another interface I’ve got a method
widgetNamed @1 (name: String) -> (widget: Widget);
Can this method return null? I’m beginning to suspect it can’t, because when it 
tries to I get an error "Pipeline call on a request that returned no 
capabilities or was already closed”. (The implementation is in C++; to return 
null it just abstains from calling context.getResults().setWidget().)

If it can’t, what is the idiomatic way to provide an optional return value? Do 
I return an exception, or do I create my own `Optional` type as a union?

—Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to capnproto+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/5862EBA9-F772-44A4-9736-72F70AAB0B86%40mooseyard.com.