let as_client ~configuration ~f =
create configuration
>>= fun client ->
begin try f ~client with
| e ->
release client
>>= fun () ->
fail (`Failure (fmt "as_client: client function threw exception: %s"
(Printexc.to_string e)))
end
>>< begin function
| `Ok () ->
release client
| `Error e ->
release client >>< fun _ ->
fail e
end