From 830a51ecc77957d50091fb8c39bbecfb026afa43 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Mon, 29 May 2006 20:33:30 +0000 Subject: [PATCH] added finally function --- DEVEL/ocaml-http/http_misc.ml | 8 ++++++++ DEVEL/ocaml-http/http_misc.mli | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/DEVEL/ocaml-http/http_misc.ml b/DEVEL/ocaml-http/http_misc.ml index abe6702c2..daa81f3b7 100644 --- a/DEVEL/ocaml-http/http_misc.ml +++ b/DEVEL/ocaml-http/http_misc.ml @@ -144,3 +144,11 @@ let list_assoc_all key pairs = let warn msg = prerr_endline (sprintf "ocaml-http WARNING: %s" msg) let error msg = prerr_endline (sprintf "ocaml-http ERROR: %s" msg) +let finally at_end f arg = + let res = + try f arg + with exn -> at_end (); raise exn + in + at_end (); + res + diff --git a/DEVEL/ocaml-http/http_misc.mli b/DEVEL/ocaml-http/http_misc.mli index b6e28e2bc..bb6a86fbb 100644 --- a/DEVEL/ocaml-http/http_misc.mli +++ b/DEVEL/ocaml-http/http_misc.mli @@ -86,3 +86,9 @@ val list_assoc_all: 'a -> ('a * 'b) list -> 'b list val warn: string -> unit (** print a warning msg to stderr. Adds trailing \n *) val error: string -> unit (** print an error msg to stderr. Adds trailing \n *) + (** @param finalizer finalization function (execution both in case of success + * and in case of raised exception + * @param f function to be invoked + * @param arg argument to be passed to function *) +val finally: (unit -> unit) -> ('a -> 'b) -> 'a -> 'b + -- 2.39.2