module Parallel: Intf
val init : ?cluster:Import.Cluster.t ->
?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.Std.Or_error.t Async.Std.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.Std.Time.Span.t | `Unlimited ] ->
?where:[ `F of unit -> string | `Local | `On of string ] ->
(unit -> 'a Async.Std.Deferred.t) ->
('a, string) Core.Std.Result.t Async.Std.Deferred.t
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:[ `At_most of Core.Std.Time.Span.t | `Unlimited ] ->
?where:[ `F of unit -> string | `Local | `On of string ] ->
(('a, 'b) Hub.t -> 'c Async.Std.Deferred.t) ->
(('a, 'b) Channel.t * ('c, string) Core.Std.Result.t Async.Std.Deferred.t)
Async.Std.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 : unit -> ('a, 'b) Hub.t Async.Std.Deferred.t
val is_worker_machine : unit -> bool
val round_robin : [> `F of unit -> string ]
val random : [> `F of unit -> string ]
val random_in : string list -> [> `F of unit -> string ]