File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 11===== dev =====
22
3- ===== Build =====
3+ ====== Breaking API changes ======
4+
5+ * Lwt_result.catch now takes a function (unit -> 'a t) rather than a promise ('a t) (#965)
6+
7+ ====== Build ======
48
59 * Remove unused dependency in dune file. (#969, Kate Deplaix)
610
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ let map_err f e = map_error f e
3131
3232let catch e =
3333 Lwt. catch
34- (fun () -> ok e )
34+ (fun () -> ok (e () ) )
3535 fail
3636
3737let get_exn e =
Original file line number Diff line number Diff line change @@ -23,9 +23,9 @@ val ok : 'a Lwt.t -> ('a, _) t
2323val error : 'b Lwt .t -> (_ , 'b ) t
2424(* * @since 5.6.0 *)
2525
26- val catch : 'a Lwt .t -> ('a , exn ) t
27- (* * [catch x] behaves like [return y] if [x] evaluates to [y],
28- and like [fail e] if [x] raises [e] *)
26+ val catch : ( unit -> 'a Lwt .t ) -> ('a , exn ) t
27+ (* * [catch x] behaves like [return y] if [x () ] evaluates to [y],
28+ and like [fail e] if [x () ] raises [e] *)
2929
3030val get_exn : ('a , exn ) t -> 'a Lwt .t
3131(* * [get_exn] is the opposite of {!catch}: it unwraps the result type,
Original file line number Diff line number Diff line change @@ -87,13 +87,25 @@ let suite =
8787
8888 test " catch"
8989 (fun () ->
90- let x = Lwt. return 0 in
90+ let x () = Lwt. return 0 in
9191 Lwt. return (Lwt_result. catch x = Lwt_result. return 0 )
9292 );
9393
9494 test " catch, error case"
9595 (fun () ->
96- let x = Lwt. fail Dummy_error in
96+ let x () = Lwt. fail Dummy_error in
97+ Lwt. return (Lwt_result. catch x = Lwt_result. fail Dummy_error )
98+ );
99+
100+ test " catch, bound raise"
101+ (fun () ->
102+ let x () = Lwt. bind Lwt. return_unit (fun () -> raise Dummy_error ) in
103+ Lwt. return (Lwt_result. catch x = Lwt_result. fail Dummy_error )
104+ );
105+
106+ test " catch, immediate raise"
107+ (fun () ->
108+ let x () = raise Dummy_error in
97109 Lwt. return (Lwt_result. catch x = Lwt_result. fail Dummy_error )
98110 );
99111
You can’t perform that action at this time.
0 commit comments