From: Stefano Zacchiroli Date: Mon, 29 May 2006 20:33:30 +0000 (+0000) Subject: added finally function X-Git-Tag: make_still_working~7296 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=8dfaf82df32a4031f06127125e3b780763604982;p=helm.git added finally function --- diff --git a/helm/software/DEVEL/ocaml-http/http_misc.ml b/helm/software/DEVEL/ocaml-http/http_misc.ml index abe6702c2..daa81f3b7 100644 --- a/helm/software/DEVEL/ocaml-http/http_misc.ml +++ b/helm/software/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/helm/software/DEVEL/ocaml-http/http_misc.mli b/helm/software/DEVEL/ocaml-http/http_misc.mli index b6e28e2bc..bb6a86fbb 100644 --- a/helm/software/DEVEL/ocaml-http/http_misc.mli +++ b/helm/software/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 +