Base: remove Lwt_utils.canceler

It has been replaced by `Lwt_canceler`
This commit is contained in:
Grégoire Henry 2018-01-27 13:35:47 +01:00
parent 9060122b26
commit a30f20c4e3
3 changed files with 3 additions and 51 deletions

View File

@ -53,8 +53,9 @@ let worker_loop () =
let worker =
lazy begin
Lwt.async begin fun () ->
let (_cancelation, cancel, _on_cancel) = Lwt_utils.canceler () in
Lwt_utils.worker "counter" ~run:worker_loop ~cancel
Lwt_utils.worker "counter"
~run:worker_loop
~cancel:(fun _ -> Lwt.return_unit)
end
end

View File

@ -18,50 +18,6 @@ let may ~f = function
let never_ending = fst (Lwt.wait ())
(* A non exception-based cancelation mechanism. Builds a [cancelation]
thread to bind / pick on, awoken when a cancelation is requested by
[cancel ()]. [on_cancel cb] registers a callback to be called at
cancelation. [cancel ()] finishes when all calbacks have completed
(sequentially), instantly when called more than once. *)
let canceler ()
: (unit -> unit Lwt.t) *
(unit -> unit Lwt.t) *
((unit -> unit Lwt.t) -> unit) =
let cancelation = LC.create () in
let cancelation_complete = LC.create () in
let cancel_hook = ref (fun () -> Lwt.return ()) in
let canceling = ref false and canceled = ref false in
let cancel () =
if !canceled then
Lwt.return ()
else if !canceling then
LC.wait cancelation_complete
else begin
canceling := true ;
LC.broadcast cancelation () ;
Lwt.finalize
!cancel_hook
(fun () ->
canceled := true ;
LC.broadcast cancelation_complete () ;
Lwt.return ()) >>= fun () ->
Lwt.return_unit
end
in
let on_cancel cb =
let hook = !cancel_hook in
cancel_hook := (fun () -> hook () >>= cb) ;
in
let cancelation () =
if !canceling then Lwt.return ()
else LC.wait cancelation
in
cancelation, cancel, on_cancel
module Idle_waiter = struct
end
type trigger =
| Absent
| Present

View File

@ -11,11 +11,6 @@ val may: f:('a -> unit Lwt.t) -> 'a option -> unit Lwt.t
val never_ending: 'a Lwt.t
val canceler: unit ->
(unit -> unit Lwt.t) *
(unit -> unit Lwt.t) *
((unit -> unit Lwt.t) -> unit)
val worker:
string ->
run:(unit -> unit Lwt.t) ->