From: Stefano Zacchiroli Date: Mon, 29 May 2006 20:33:30 +0000 (+0000) Subject: added finally function X-Git-Tag: 0.4.95@7852~1399 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=830a51ecc77957d50091fb8c39bbecfb026afa43;p=helm.git added finally function --- 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 +