package distributed

  1. Overview
  2. Docs

Abstract type which can perform monadic concurrent IO.

type 'a t

The monadic light weight thread type returning value 'a.

type 'a stream

An unbounded stream holding values of 'a.

type input_channel

A type to represent a non-blocking input channel

type output_channel

A type to represent a non-blocking output channel

type server

A type to represent a server

type logger

A type to represent a logger

exception Timeout

Exception raised by time out operations

type level =
  1. | Debug
  2. | Info
  3. | Notice
  4. | Warning
  5. | Error
  6. | Fatal
    (*

    Type to represent levels of a log message.

    *)
val lib_name : string

The name of the implementation, for logging purposes.

val lib_version : string

The version implementation, for logging purposes.

val lib_description : string

A description of the implementation (e.g., the url of the code repository ), for logging purposes.

val return : 'a -> 'a t

return v creates a light weight thread returning v.

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t

bind t f is a thread which first waits for the thread t to terminate and then, if the thread succeeds, behaves as the application of function f to the return value of t. If the thread t fails, bind t f also fails, with the same exception.

val ignore_result : 'a t -> unit

ignore_result t is like Pervasives.ignore t except that: if t already failed, it raises the exception now, if t is sleeping and fails later, the exception will be given to ​async_exception_hook.

val fail : exn -> 'a t

fail e is a thread that fails with the exception e.

val catch : (unit -> 'a t) -> (exn -> 'a t) -> 'a t

catch t f is a thread that behaves as the thread t () if this thread succeeds. If the thread t () fails with some exception, catch t f behaves as the application of f to this exception.

val async : (unit -> 'a t) -> unit

async f starts a thread without waiting for the result.

val create_stream : unit -> 'a stream * ('a option -> unit)

create () returns a new stream and a push function.

val get : 'a stream -> 'a option t

get st removes and returns the first element of the stream, if any. Will block if the stream is empty.

val stream_append : 'a stream -> 'a stream -> 'a stream

stream_append s1 s2 returns a stream which returns all elements of s1, then all elements of s2.

val close_input : input_channel -> unit t

close ch closes the given channel immediately.

val close_output : output_channel -> unit t

close ch closes the given channel. It performs all pending actions, flushes it and closes it.

val read_value : input_channel -> 'a t

read_value ic reads a marshalled value from ic.

val write_value : output_channel -> ?flags:Batteries.Marshal.extern_flags list -> 'a -> unit t

write_value oc ?flags x marshals the value x to oc.

open_connection addr opens a connection to the given address and returns two channels for using it.

val establish_server : ?backlog:int -> Batteries.Unix.sockaddr -> ((input_channel * output_channel) -> unit) -> server

establish_server ?backlog sockaddr f creates a server which will listen for incoming connections. New connections are passed to f. Note that f must not raise any exception. Backlog is the argument passed to Lwt_unix.listen.

val shutdown_server : server -> unit

shutdown_server server will shutdown server.

val log : ?exn:exn -> ?location:(string * int * int) -> logger:logger -> level:level -> string -> unit t

log ?exn ?location logger level message logs a message using logger. If exn is provided, then its string representation (= Printexc.to_string exn) will be append to the message, and if possible the back trace will also be logged. Location contains the location of the logging directive, it is of the form (file_name, line, column).

val sleep : float -> unit t

sleep d is a thread that remains suspended for d seconds and then terminates.

val timeout : float -> 'a t

timeout d is a thread that remains suspended for d seconds and then fails with ​Timeout.

val choose : 'a t list -> 'a t

choose l behaves as the first thread in l to terminate. If several threads are already terminated, one is chosen at random.

val pick : 'a t list -> 'a t

pick l is the same as ​choose, except that it cancels all sleeping threads when one terminates.

val nchoose : 'a t list -> 'a list t

nchoose l returns the value of all that have successfully terminated. If all threads are sleeping, it waits for at least one to terminates. If one the threads of l fails, nchoose fails with the same exception.

val at_exit : (unit -> unit t) -> unit

at_exit fn will call fn on program exit.

OCaml

Innovation. Community. Security.