Module Async_unix__.Shutdown
val shutdown : ?force:unit Async_unix__.Import.Deferred.t -> int -> unit
shutdown ?force status
initiates shutdown, which runs all theat_shutdown
functions, waits for them to finish, and then exits with the supplied status. Theat_shutdown
functions can block -- one can use~force
to forcibly exit (with status 1) if theat_shutdown
functions do not finish in a reasonable amount of time.By default,
force
isafter (sec 10.)
.Repeated calls to
shutdown
with the same status will have no effect. Any call toshutdown
with nonzero status will cause that to be the status that is exited with. A call toshutdown
with different nonzero status from the original call will raise.
val shutdown_on_unhandled_exn : unit -> unit
shutdown_on_unhandled_exn ()
arranges things so that whenever there is an asynchronous unhandled exception, an error message is printed to stderr andshutdown 1
is called. This is useful when one wants to ensure thatat_shutdown
handlers run when there is an unhandled exception. Callingshutdown_on_unhandled_exn
ensures thatScheduler.go
will not raise due to an unhandled exception, and instead that the program will exit onceat_shutdown
handlers finish.
val exit : ?force:unit Async_unix__.Import.Deferred.t -> int -> _ Async_unix__.Import.Deferred.t
exit ?force status
isshutdown ?force status; Deferred.never ()
.We do not have an exit function that returns a non-deferred:
val exit : ?force:unit Deferred.t -> int -> _
Such a function should not exist, for the same reason that we do not have:
val block : 'a Deferred.t -> 'a
The semantics of such an exit function would allow one to block a running Async job, and to switch to another one (to run the
at_shutdown
handlers), without expressing that switch in the type system via aDeferred.t
. That would eliminate all the nice reasoning guarantees that Async gives about concurrent jobs.
val default_force : unit -> unit -> unit Async_unix__.Import.Deferred.t
default_force
returns the defaultforce
value used byshutdown
andexit
.
val set_default_force : (unit -> unit Async_unix__.Import.Deferred.t) -> unit
set_default_force f
sets the defaultforce
value used byshutdown
andexit
tof
. Initially, the default value isfun () -> after (sec 10.)
. A subsequent call toshutdown
orexit
that doesn't supply~force
will callf
and will force shutdown when its result becomes determined.set_default_force
has no effect ifshutdown
orexit
has already been called, or if the next call toshutdown
orexit
supplies~force
.set_default_force
is useful for applications that callshutdown
indirectly via a library, yet want to modify its behavior.
val shutting_down : unit -> [ `No | `Yes of int ]
shutting_down ()
reports whether we are currently shutting down, and if so, with what status.
val is_shutting_down : unit -> bool
val at_shutdown : (unit -> unit Async_unix__.Import.Deferred.t) -> unit
at_shutdown f
causesf ()
to be run whenshutdown
is called, and forshutdown
to wait until the returned deferred finishes. Iff
raises (synchronously or asynchronously), then the exception is printed to stderr and the program exits nonzero, irrespective of the status supplied toshutdown
.If
shutdown
has already been called, then callingat_shutdown f
does nothing.The functions supplied to
at_shutdown
are run in parallel on shutdown.
val don't_finish_before : unit Async_unix__.Import.Deferred.t -> unit
don't_finish_before d
causesshutdown
to wait untild
becomes determined before finishing. It is likeat_shutdown (fun _ -> d)
, except it is more efficient, and will not take any space onced
is determined. There is a singleat_shutdown
shared among all deferreds supplied todon't_finish_before
.don't_finish_before
does not override theforce
argument passed to shutdown.