Client/Context_unix: code style
This commit is contained in:
parent
24355f0ae9
commit
e35e263fd6
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user