From e35e263fd6a424eb3244f313d32e38dfc8750e1b Mon Sep 17 00:00:00 2001 From: MBourgoin Date: Tue, 6 Nov 2018 13:10:24 +0100 Subject: [PATCH] Client/Context_unix: code style --- .../client_context_unix.ml | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/lib_client_base_unix/client_context_unix.ml b/src/lib_client_base_unix/client_context_unix.ml index d6c633d94..67e0429bd 100644 --- a/src/lib_client_base_unix/client_context_unix.ml +++ b/src/lib_client_base_unix/client_context_unix.ml @@ -32,27 +32,25 @@ class unix_wallet ~base_dir : wallet = object (self) base_dir (Str.(global_replace (regexp_string " ") "_" alias_name) ^ "s") - method with_lock : type a. ( unit -> a Lwt.t) -> a Lwt.t = + method with_lock : type a. (unit -> a Lwt.t) -> a Lwt.t = (fun f -> let unlock fd = let fd = Lwt_unix.unix_file_descr fd in - Unix.lockf fd Unix.F_ULOCK 0; - Unix.close fd - in + Unix.lockf fd Unix.F_ULOCK 0 ; + Unix.close fd in let lock () = Lwt_unix.openfile (Filename.concat base_dir "wallet_lock") - Lwt_unix.[O_CREAT; O_WRONLY] 0o644 >>= fun fd -> + Lwt_unix.[ O_CREAT ; O_WRONLY ] 0o644 >>= fun fd -> Lwt_unix.lockf fd Unix.F_LOCK 0 >>= fun () -> - Lwt.return (fd,(Lwt_unix.on_signal Sys.sigint - (fun _s -> - unlock fd; - exit 0 (* exit code? *) ))) - in - lock () >>= fun (fd,sh) -> + Lwt.return (fd, (Lwt_unix.on_signal Sys.sigint + (fun _s -> + unlock fd ; + exit 0 (* exit code? *) ))) in + lock () >>= fun (fd, sh) -> (* catch might be useless if f always uses the error monad *) - Lwt.catch f (function e -> Lwt.return (unlock fd; raise e)) >>= fun res -> + Lwt.catch f (function e -> Lwt.return (unlock fd ; raise e)) >>= fun res -> Lwt.return (unlock fd) >>= fun () -> - Lwt_unix.disable_signal_handler sh; + Lwt_unix.disable_signal_handler sh ; Lwt.return res) method load : type a. string -> default:a -> a Data_encoding.encoding -> a tzresult Lwt.t =