Module Monitor

module Monitor: Monitor

type t = Execution_context.t Raw_monitor.t 
val sexp_of_t : t -> Sexplib.Sexp.t
val create : ?name:string -> unit -> t
create () returns a new monitor whose parent is the current monitor
val name : t -> string
name t returns the name of the monitor, or a unique id if no name was supplied to create.
val current : unit -> t
current () returns the current monitor
val errors : t -> exn Raw_async_stream.t
errors t returns a stream of all subsequent errors that monitor t sees.
val error : t -> exn Deferred.t
error t returns a deferred that becomes defined if the monitor ever sees an error. Calling error t does not count as "listening for errors", and if no one has called errors t to listen, then errors will still be raised up the monitor tree.
val extract_exn : exn -> exn
extract_exn exn extracts the exn from an error exn that comes from a monitor. If it is not supplied such an error exn, it returns the exn itself.
val has_seen_error : t -> bool
has_seen_error t returns true iff the monitor has ever seen an error.
val send_exn : t -> ?backtrace:[ `Get | `This of string ] -> exn -> unit
send_exn t exn ?backtrace sends the exception exn as an error to be handled monitor t. By default, the error will not contain a backtrace. However, the caller can supply one using `This, or use `Get to request that send_exn obtain one using Exn.backtrace ().
val try_with : ?name:string ->
(unit -> 'a Deferred.t) -> ('a, exn) Core.Std.Result.t Deferred.t
try_with f schedules f () to run in a monitor and returns the result as Ok x if f finishes normally, or returns Error e if there is some error. Once a result is returned, any subsequent errors raised by f () are ignored. try_with always returns a deferred immediately and does not raise.

The name argument is used to give a name to the monitor the computation will be running in. This name will appear when printing errors.

val try_with_raise_rest : ?name:string ->
(unit -> 'a Deferred.t) -> ('a, exn) Core.Std.Result.t Deferred.t
try_with_raise_rest f is the same as try_with f, except that subsequent errors raised by f () are reraised to the monitor that called try_with_raise_rest.
val handle_errors : ?name:string -> (unit -> 'a Deferred.t) -> (exn -> unit) -> 'a Deferred.t
handle_errors ?name f handler runs f () inside a new monitor with the optionally supplied name, and calls handler error on every error raised to that monitor. Any error raised by handler goes to the monitor in effect when handle_errors was called.
val catch_stream : ?name:string -> (unit -> unit) -> exn Raw_async_stream.t
catch_stream ?name f runs f () inside a new monitor m and returns the stream of errors raised to m.
val catch : ?name:string -> (unit -> unit) -> exn Deferred.t
catch ?name f runs f () inside a new monitor m and returns the first error raised to m.
val protect : ?name:string ->
(unit -> 'a Deferred.t) -> finally:(unit -> unit Deferred.t) -> 'a Deferred.t
protect f ~finally runs f () and then finally regardless of the success or failure of f. Re-raises any exception thrown by f or returns whatever f returned.

The name argument is used to give a name to the monitor the computation will be running in. This name will appear when printing the errors.

val main : t
module Exported_for_scheduler: sig .. end