From cc83d8444b61554a6c89549284dd37956b4aff41 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Mon, 10 Oct 2016 15:37:01 +0200 Subject: [PATCH] add a safe mode for workers --- src/utils/lwt_utils.ml | 5 +++-- src/utils/lwt_utils.mli | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/lwt_utils.ml b/src/utils/lwt_utils.ml index b2fcf5e15..cee2b3f7b 100644 --- a/src/utils/lwt_utils.ml +++ b/src/utils/lwt_utils.ml @@ -111,11 +111,12 @@ let queue () : ('a -> unit) * (unit -> 'a list Lwt.t) = queue, wait (* A worker launcher, takes a cancel callback to call upon *) -let worker name ~run ~cancel = +let worker ?(safe=false) name ~run ~cancel = let stop = LC.create () in let fail e = log_error "%s worker failed with %s" name (Printexc.to_string e) ; - cancel () >>= fun () -> Lwt.fail e + cancel () >>= fun () -> + if safe then Lwt.return_unit else Lwt.fail e in let waiter = LC.wait stop in log_info "%s worker started" name ; diff --git a/src/utils/lwt_utils.mli b/src/utils/lwt_utils.mli index 7f42580b7..b3ddc40fa 100644 --- a/src/utils/lwt_utils.mli +++ b/src/utils/lwt_utils.mli @@ -15,6 +15,7 @@ val canceler : unit -> ((unit -> unit Lwt.t) -> unit) val worker: + ?safe:bool -> string -> run:(unit -> unit Lwt.t) -> cancel:(unit -> unit Lwt.t) ->