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