package async_parallel

  1. Overview
  2. Docs
val init : ?cluster:Import.Cluster.t -> ?close_stdout_and_stderr:bool -> ?fail_if_async_has_been_initialized:bool -> unit -> unit

init initializes the system and creates the master process. master_init, if specified, is called in the master process and may be used for cleanup/initialization such as closing file descriptors. init should be called before any threads are created. If your program daemonizes, call init after you daemonize, but before you start the async scheduler. init may only be called once.

If cluster is specified, and it specifies a set of host names or ips that you can ssh to without a password, and have permission to run programs on, then a master process will also be started on every machine in the cluster, and worker processes may be spawned on any machine in the cluster. Note that in ord

val shutdown : unit -> unit Core.Or_error.t Async.Deferred.t

shutdown requests that the master process kill all workers and then shutdown. It then waits for the master process to exit. shutdown returns Ok () when the master exits without problems; otherwise it returns an error.

val run : ?buffer_age_limit:[ `At_most of Core.Time.Span.t | `Unlimited ] -> ?where:[ `Local | `On of string | `F of unit -> string ] -> (unit -> 'a Async.Deferred.t) -> ('a, string) Core.Result.t Async.Deferred.t

Run the specified closure in another process and return its result.

If where is specified, it controls which machine the process is spawned on. The default is the local machine. You must have passed a list of machines to init in order to use `On, or `Random_on. An exception will be raised if you try to use a machine you didn't pass to init.

The closure you pass may not contain custom blocks with unimplemented serialization functions or Abstract values. Anything you can't pass to Marshal, you can't pass to spawn.

val spawn : ?buffer_age_limit:Async.Writer.buffer_age_limit -> ?where:[ `Local | `On of string | `F of unit -> string ] -> (('a, 'b) Hub.t -> 'c Async.Deferred.t) -> (('a, 'b) Channel.t * ('c, string) Core.Result.t Async.Deferred.t) Async.Deferred.t

spawn f spawns a process running f, supplying f a hub that it may use to communicate with other processes. f should listen to the hub to receive messages from the clients. spawn returns a channel connected to f's hub, and a deferred that will become determined if f returns.

There is no guarantee that the deferred returned by this function will become determined before the spawned process runs, as such the following code is a race, and may never return.

| spawn (fun hub -> Hub.send_to_all hub `Hello; Deferred.never ()) | >>= fun (channel, _) -> | Channel.read channel | >>= fun `Hello -> | ...

It IS however guaranteed that the spawned process is listening when the deferred returned by this function is returned, it is theirfore recommended that the spawning process initiate the first communication.

If where is specified, it controls which machine the process is spawned on. The default is the local machine. You must have passed a list of machines to init in order to use `On, or `Random_on. An exception will be raised if you try to use a machine you didn't pass to init.

The closure you pass may not contain custom blocks with unimplemented serialization functions or Abstract values. Anything you can't pass to Marshal, you can't pass to spawn.

val hub : ?buffer_age_limit:Async.Writer.buffer_age_limit -> unit -> (_, _) Hub.t Async.Deferred.t

create a new hub.

val is_worker_machine : unit -> bool

returns true if this is a worker machine. See the notes on running on multiple machines in Std.ml.

val round_robin : [> `F of unit -> string ]
val random : [> `F of unit -> string ]
val random_in : string list -> [> `F of unit -> string ]
OCaml

Innovation. Community. Security.