Skip to content

Commit

Permalink
Rename cancelable into wrap_in_cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-proust committed May 22, 2020
1 parent 9acc5c5 commit 727e06d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/core/lwt.ml
Expand Up @@ -1550,7 +1550,7 @@ sig

val protected : 'a t -> 'a t
val no_cancel : 'a t -> 'a t
val cancelable : 'a t -> 'a t
val wrap_in_cancelable : 'a t -> 'a t
end =
struct
let new_pending ~how_to_cancel =
Expand Down Expand Up @@ -1687,7 +1687,7 @@ struct

to_public_promise p'

let cancelable p =
let wrap_in_cancelable p =
let Internal p_internal = to_internal_promise p in
let p_underlying = underlying p_internal in
match p_underlying.state with
Expand Down
8 changes: 4 additions & 4 deletions src/core/lwt.mli
Expand Up @@ -1186,10 +1186,10 @@ val no_cancel : 'a t -> 'a t
Note that [p'] can still be canceled if [p] is canceled. [Lwt.no_cancel]
only prevents cancellation of [p] and [p'] through [p']. *)

val cancelable : 'a t -> 'a t
(** [Lwt.cancelable p] creates a {{: #VALcancel} cancelable} promise [p'] with
the same state as [p]. Cancellation carries onto [p], but [p'] is rejected
with {!Lwt.Canceled} even if [p] is not cancelable. *)
val wrap_in_cancelable : 'a t -> 'a t
(** [Lwt.wrap_in_cancelable p] creates a {{: #VALcancel} cancelable} promise
[p'] with the same state as [p]. Cancellation carries onto [p], but [p'] is
rejected with {!Lwt.Canceled} even if [p] is not cancelable. *)



Expand Down
22 changes: 11 additions & 11 deletions test/core/test_lwt.ml
Expand Up @@ -2720,9 +2720,9 @@ let protected_tests = suite "protected" [
]
let suites = suites @ [protected_tests]

let cancelable_tests = suite "cancelable" [
let cancelable_tests = suite "wrap_in_cancelable" [
test "fulfilled" begin fun () ->
let p = Lwt.cancelable (Lwt.return ()) in
let p = Lwt.wrap_in_cancelable (Lwt.return ()) in
Lwt.return (Lwt.state p = Lwt.Return ())
end;

Expand All @@ -2733,40 +2733,40 @@ let cancelable_tests = suite "cancelable" [

test "pending(task)" begin fun () ->
let p, _ = Lwt.task () in
let p' = Lwt.cancelable p in
let p' = Lwt.wrap_in_cancelable p in
Lwt.return (Lwt.state p = Lwt.Sleep && Lwt.state p' = Lwt.Sleep)
end;

test "pending(task), fulfilled" begin fun () ->
let p, r = Lwt.task () in
let p' = Lwt.cancelable p in
let p' = Lwt.wrap_in_cancelable p in
Lwt.wakeup r "foo";
Lwt.return (Lwt.state p = Lwt.Return "foo" && Lwt.state p' = Lwt.Return "foo")
end;

test "pending(task), canceled" begin fun () ->
let p, _ = Lwt.task () in
let p' = Lwt.cancelable p in
let p' = Lwt.wrap_in_cancelable p in
Lwt.cancel p';
Lwt.return (Lwt.state p = Lwt.Fail Lwt.Canceled && Lwt.state p' = Lwt.Fail Lwt.Canceled)
end;

test "pending(wait)" begin fun () ->
let p, _ = Lwt.wait () in
let p' = Lwt.cancelable p in
let p' = Lwt.wrap_in_cancelable p in
Lwt.return (Lwt.state p = Lwt.Sleep && Lwt.state p' = Lwt.Sleep)
end;

test "pending(wait), fulfilled" begin fun () ->
let p, r = Lwt.wait () in
let p' = Lwt.cancelable p in
let p' = Lwt.wrap_in_cancelable p in
Lwt.wakeup r "foo";
Lwt.return (Lwt.state p = Lwt.Return "foo" && Lwt.state p' = Lwt.Return "foo")
end;

test "pending(wait), canceled" begin fun () ->
let p, _ = Lwt.wait () in
let p' = Lwt.cancelable p in
let p' = Lwt.wrap_in_cancelable p in
Lwt.cancel p';
Lwt.return (Lwt.state p = Lwt.Sleep && Lwt.state p = Lwt.Fail Lwt.Canceled)
end;
Expand All @@ -2789,11 +2789,11 @@ let cancelable_tests = suite "cancelable" [
(Lwt.state p = Lwt.Return "foo" && Lwt.state p' = Lwt.Fail Lwt.Canceled)
end;

(* Implementation detail: [p' = Lwt.cancelable _] can still be resolved if it
becomes a proxy. *)
(* Implementation detail: [p' = Lwt.wrap_in_cancelable _] can still be
resolved if it becomes a proxy. *)
test "pending, proxy" begin fun () ->
let p1, r1 = Lwt.task () in
let p2 = Lwt.cancelable p1 in
let p2 = Lwt.wrap_in_cancelable p1 in

(* Make p2 a proxy for p4; p3 is just needed to suspend the bind, in order
to callback the code that makes p2 a proxy. *)
Expand Down

0 comments on commit 727e06d

Please sign in to comment.