Skip to content

Commit

Permalink
Handle uncaught exceptions in Lwt_react.of_stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
paurkedal committed Oct 7, 2020
1 parent 50fd7a4 commit 83e28d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/core/lwt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ val async_exception_hook : (exn -> unit) ref
(** Reference to a function, to be called on an "unhandled" exception.
This reference is used by {!Lwt.async}, {!Lwt.on_cancel}, {!Lwt.on_success},
{!Lwt.on_failure}, {!Lwt.on_termination}, {!Lwt.on_any}, and the deprecated
{!Lwt.ignore_result}.
{!Lwt.on_failure}, {!Lwt.on_termination}, {!Lwt.on_any},
{!Lwt_react.of_stream}, and the deprecated {!Lwt.ignore_result}.
The initial, default implementation prints the exception, then terminates
the process with non-zero exit status, as if the exception had reached the
Expand Down
3 changes: 2 additions & 1 deletion src/react/lwt_react.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ module E = struct
let of_stream stream =
let event, push = create () in
let t =
Lwt.pause () >>= fun () -> Lwt_stream.iter (fun v -> push v) stream in
Lwt.pause () >>= fun () ->
Lwt_stream.iter (fun v -> try push v with exn -> !Lwt.async_exception_hook exn) stream in
with_finaliser (cancel_thread t) event

let delay thread =
Expand Down
6 changes: 5 additions & 1 deletion src/react/lwt_react.mli
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ module E : sig

val of_stream : 'a Lwt_stream.t -> 'a event
(** [of_stream stream] creates an event which occurs each time a
value is available on the stream. *)
value is available on the stream.
If updating the event causes an exception at any point during the update
step, the excpetion is passed to [!]{!Lwt.async_exception_hook}, which
terminates the process by default. *)

val delay : 'a event Lwt.t -> 'a event
(** [delay promise] is an event which does not occur until
Expand Down

0 comments on commit 83e28d0

Please sign in to comment.