Module Async_unix.Shutdown
For shutting down an Async program.
val shutdown : ?force:unit Async_unix__.Import.Deferred.t -> int -> unitshutdown ?force statusinitiates shutdown, which runs all theat_shutdownfunctions, waits for them to finish, and then exits with the supplied status. Theat_shutdownfunctions can block -- one can use~forceto forcibly exit (with status 1) if theat_shutdownfunctions do not finish in a reasonable amount of time.By default,
forceisafter (sec 10.).Repeated calls to
shutdownwith the same status will have no effect. Any call toshutdownwith nonzero status will cause that to be the status that is exited with. A call toshutdownwith different nonzero status from the original call will raise.
val shutdown_on_unhandled_exn : unit -> unitshutdown_on_unhandled_exn ()arranges things so that whenever there is an asynchronous unhandled exception, an error message is printed to stderr andshutdown 1is called. This is useful when one wants to ensure thatat_shutdownhandlers run when there is an unhandled exception. Callingshutdown_on_unhandled_exnensures thatScheduler.gowill not raise due to an unhandled exception, and instead that the program will exit onceat_shutdownhandlers finish.
val exit : ?force:unit Async_unix__.Import.Deferred.t -> int -> _ Async_unix__.Import.Deferred.texit ?force statusisshutdown ?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 -> 'aThe 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_shutdownhandlers), 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.tdefault_forcereturns the defaultforcevalue used byshutdownandexit.
val set_default_force : (unit -> unit Async_unix__.Import.Deferred.t) -> unitset_default_force fsets the defaultforcevalue used byshutdownandexittof. Initially, the default value isfun () -> after (sec 10.). A subsequent call toshutdownorexitthat doesn't supply~forcewill callfand will force shutdown when its result becomes determined.set_default_forcehas no effect ifshutdownorexithas already been called, or if the next call toshutdownorexitsupplies~force.set_default_forceis useful for applications that callshutdownindirectly 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 at_shutdown : (unit -> unit Async_unix__.Import.Deferred.t) -> unitat_shutdown fcausesf ()to be run whenshutdownis called, and forshutdownto wait until the returned deferred finishes. Iffraises (synchronously or asynchronously), then the exception is printed to stderr and the program exits nonzero, irrespective of the status supplied toshutdown.If
shutdownhas already been called, then callingat_shutdown fdoes nothing.The functions supplied to
at_shutdownare run in parallel on shutdown.
val don't_finish_before : unit Async_unix__.Import.Deferred.t -> unitdon't_finish_before dcausesshutdownto wait untildbecomes determined before finishing. It is likeat_shutdown (fun _ -> d), except it is more efficient, and will not take any space oncedis determined. There is a singleat_shutdownshared among all deferreds supplied todon't_finish_before.don't_finish_beforedoes not override theforceargument passed to shutdown.