Skip to content

Commit

Permalink
Lwt_seq: some fixes for exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-proust committed Mar 5, 2021
1 parent f37b90d commit f25122c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/core/lwt_seq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,24 @@ let to_list seq =
x :: l

let rec of_seq seq =
try
match seq () with
| Seq.Nil -> empty
| Seq.Cons (x, next) ->
cons x (of_seq next)
with exn ->
fun () -> raise exn
match seq () with
| Seq.Nil -> empty
| Seq.Cons (x, next) ->
cons x (of_seq next)
| exception exn -> Lwt.fail exn

let rec of_seq_lwt (seq: 'a Lwt.t Seq.t): 'a t Lwt.t =
match seq () with
| Seq.Nil -> Lwt.return empty
| Seq.Cons (x, next) ->
Lwt.catch (fun () ->
let* x = x in
let+ next = of_seq_lwt next in
cons x next)
(fun exc -> Lwt.return (fun () -> raise exc))
let* x = x in
let+ next = of_seq_lwt next in
cons x next
let of_seq_lwt (seq: 'a Lwt.t Seq.t): 'a t Lwt.t =
match seq () with
| Seq.Nil -> Lwt.return empty
| Seq.Cons (x, next) ->
let* x = x in
let+ next = of_seq_lwt next in
cons x next
| exception exc -> Lwt.fail exc

0 comments on commit f25122c

Please sign in to comment.