Skip to content

Commit

Permalink
Revert "deprecate Lwt_result.catch, introduce catch_f instead"
Browse files Browse the repository at this point in the history
This reverts commit 319aa57.
  • Loading branch information
raphael-proust committed Oct 24, 2022
1 parent 68c0714 commit c65633a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
5 changes: 0 additions & 5 deletions src/core/lwt_result.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ let map_error f e =
let map_err f e = map_error f e

let catch e =
Lwt.catch
(fun () -> ok e)
fail

let catch_f e =
Lwt.catch
(fun () -> ok (e ()))
fail
Expand Down
7 changes: 2 additions & 5 deletions src/core/lwt_result.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ val ok : 'a Lwt.t -> ('a, _) t
val error : 'b Lwt.t -> (_, 'b) t
(** @since 5.6.0 *)

val catch_f : (unit -> 'a Lwt.t) -> ('a, exn) t
(** [catch_f x] behaves like [return y] if [x ()] evaluates to [y],
val catch : (unit -> 'a Lwt.t) -> ('a, exn) t
(** [catch x] behaves like [return y] if [x ()] evaluates to [y],
and like [fail e] if [x ()] raises [e] *)

val get_exn : ('a, exn) t -> 'a Lwt.t
Expand Down Expand Up @@ -124,6 +124,3 @@ val map_err : ('e1 -> 'e2) -> ('a,'e1) t -> ('a,'e2) t [@@deprecated "Alias to m

val bind_lwt_err : ('a,'e1) t -> ('e1 -> 'e2 Lwt.t) -> ('a,'e2) t [@@deprecated "Alias to bind_lwt_error"]
(** @deprecated Alias to [bind_lwt_error] since 5.6.0. *)

val catch : 'a Lwt.t -> ('a, exn) t [@@deprecated "Unsafe, use catch_f instead"]
(** @deprecated This function is unsafe, it may let exceptions escape, use [catch_f] instead *)
16 changes: 8 additions & 8 deletions test/core/test_lwt_result.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ let suite =
Lwt.return (Lwt_result.error x = Lwt_result.fail 0)
);

test "catch_f"
test "catch"
(fun () ->
let x () = Lwt.return 0 in
Lwt.return (Lwt_result.catch_f x = Lwt_result.return 0)
Lwt.return (Lwt_result.catch x = Lwt_result.return 0)
);

test "catch_f, error case"
test "catch, error case"
(fun () ->
let x () = Lwt.fail Dummy_error in
Lwt.return (Lwt_result.catch_f x = Lwt_result.fail Dummy_error)
Lwt.return (Lwt_result.catch x = Lwt_result.fail Dummy_error)
);

test "catch_f, bound raise"
test "catch, bound raise"
(fun () ->
let x () = Lwt.bind Lwt.return_unit (fun () -> raise Dummy_error) in
Lwt.return (Lwt_result.catch_f x = Lwt_result.fail Dummy_error)
Lwt.return (Lwt_result.catch x = Lwt_result.fail Dummy_error)
);

test "catch_f, immediate raise"
test "catch, immediate raise"
(fun () ->
let x () = raise Dummy_error in
Lwt.return (Lwt_result.catch_f x = Lwt_result.fail Dummy_error)
Lwt.return (Lwt_result.catch x = Lwt_result.fail Dummy_error)
);

test "get_exn"
Expand Down

0 comments on commit c65633a

Please sign in to comment.