add a safe mode for workers

This commit is contained in:
Vincent Bernardoff 2016-10-10 15:37:01 +02:00
parent 9748ffcda6
commit cc83d8444b
2 changed files with 4 additions and 2 deletions

View File

@ -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 ;

View File

@ -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) ->