module Shutdown: Shutdown
val shutdown : ?force:unit Import.Deferred.t -> int -> unit
shutdown ?force status
initiates shutdown, which runs all the at_shutdown
functions, waits for them to finish, and then exits with the supplied status. The
at_shutdown
functions can block -- one can use ~force
to forcibly exit (with
status 1) if the at_shutdown
functions do not finish in a reasonable amount of time.
By default, force
is after (sec 10.)
.
Repeated calls to shutdown
with the same status will have no effect. Any call to
shutdown
with nonzero status will cause that to be the status that is exited with.
A call to shutdown
with different nonzero status from the original call will
raise.
val exit : ?force:unit Import.Deferred.t -> int -> 'a Import.Deferred.t
exit ?force status
is shutdown ?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 a Deferred.t
. That would eliminate all the nice
reasoning guarantees that async gives about concurrent jobs.
val shutting_down : unit -> [ `No | `Yes of int ]
shutting_down ()
reports whether we are currently shutting down, and if so, with
what status.val at_shutdown : (unit -> unit Import.Deferred.t) -> unit
at_shutdown f
causes f ()
to be run when shutdown
is called, and for shutdown
to wait until the returned deferred finishes.