From bd8760acad95f1a3dd8e79acac606fb30b21b3e0 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Wed, 19 Apr 2023 20:34:39 -0400 Subject: [PATCH] Add csp.Client function to send capabilities over a channel. --- pkg/csp/chan.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/csp/chan.go b/pkg/csp/chan.go index e883712e..664ce66e 100644 --- a/pkg/csp/chan.go +++ b/pkg/csp/chan.go @@ -216,6 +216,16 @@ func Ptr(ptr capnp.Ptr) Value { } } +// Client takes any client-like type and converts it into a value +// capable of being sent through a channel. +func Client[T ~capnp.ClientKind](t T) Value { + return func(ps api.Sender_send_Params) error { + id := ps.Message().CapTable().Add(capnp.Client(t)) + ifc := capnp.NewInterface(ps.Segment(), id) + return ps.SetValue(ifc.ToPtr()) + } +} + // Struct takes any capnp struct and converts it into a value // capable of being sent through a channel. func Struct[T ~capnp.StructKind](t T) Value {