Skip to content

Commit 7d3d06b

Browse files
committed
Use Fun.protect instead of protectx
1 parent 85eddc1 commit 7d3d06b

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

lib/postgresql.ml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -797,16 +797,6 @@ external conndefaults : unit -> conninfo_option array = "PQconndefaults_stub"
797797

798798
exception Finally of exn * exn
799799

800-
let protectx ~f ~(finally : unit -> unit) =
801-
let res =
802-
try f ()
803-
with exn ->
804-
(try finally () with final_exn -> raise (Finally (exn, final_exn)));
805-
raise exn
806-
in
807-
finally ();
808-
res
809-
810800
module type Mutex = sig
811801
type t
812802

@@ -973,13 +963,13 @@ module Connection (Mutex : Mutex) = struct
973963
failwith "Postgresql.check_null: connection already finished"
974964
in
975965
let wrap_conn f =
976-
protectx
977-
~f:(fun _ ->
966+
Fun.protect
967+
~finally:(fun _ -> Mutex.unlock conn_mtx)
968+
(fun _ ->
978969
Mutex.lock conn_mtx;
979970
check_null ();
980971
(* Check again in case the world has changed *)
981972
f my_conn)
982-
~finally:(fun _ -> Mutex.unlock conn_mtx)
983973
in
984974
let signal_error conn =
985975
raise (Error (Connection_failure (Stub.error_message conn)))

0 commit comments

Comments
 (0)