diff --git a/capnp-rpc-lwt/capnp_rpc_lwt.mli b/capnp-rpc-lwt/capnp_rpc_lwt.mli index d72aab9f3..c90ddda6a 100644 --- a/capnp-rpc-lwt/capnp_rpc_lwt.mli +++ b/capnp-rpc-lwt/capnp_rpc_lwt.mli @@ -252,6 +252,12 @@ module Service : sig val fail : ?ty:Capnp_rpc.Exception.ty -> ('a, Format.formatter, unit, 'b StructRef.t) format4 -> 'a (** [fail msg] is an exception with reason [msg]. *) + + val fail_lwt : + ?ty:Capnp_rpc.Exception.ty -> + ('a, Format.formatter, unit, (_, [> `Capnp of Capnp_rpc.Error.t]) Lwt_result.t) format4 -> + 'a + (** [fail_lwt msg] is like [fail msg], but can be used with [return_lwt]. *) end (**/**) diff --git a/capnp-rpc-lwt/service.ml b/capnp-rpc-lwt/service.ml index de6927077..1bb0ddcdf 100644 --- a/capnp-rpc-lwt/service.ml +++ b/capnp-rpc-lwt/service.ml @@ -62,8 +62,8 @@ let return_empty () = return @@ Response.create_empty () (* A convenient way to implement a simple blocking local function, where - pipelining is not supported (further messages will be queued up at this - host until it returns). *) + pipelining is not supported (messages sent to the result promise will be + queued up at this host until it returns). *) let return_lwt fn = let result, resolver = Local_struct_promise.make () in Lwt.async (fun () -> @@ -81,3 +81,7 @@ let return_lwt fn = result let fail = Core_types.fail + +let fail_lwt ?ty fmt = + fmt |> Fmt.kstr @@ fun msg -> + Lwt_result.fail (`Capnp (`Exception (Capnp_rpc.Exception.v ?ty msg)))