Type of a stream holding values of type
Naming convention: in this module all function taking a function which is applied to all element of the streams are suffixed by:
_swhen the function returns a thread and calls are serialised
_pwhen the function returns a thread and calls are parallelised
Exception raised by the push function of a push-stream when
pushing an element after the end of stream (
= None) have been
create () returns a new stream and a push function.
create_with_reference () returns a new stream and a push
function. The last function allows to set a reference to an
external source. This prevent the external source from being
For example, to convert a reactive event to a stream:
let stream, push, set_ref = Lwt_stream.create_with_reference () in set_ref (map_event push event)
Exception raised by the push function of a bounded push-stream when the stream queue is full and a thread is already waiting to push an element.
Size of the stream.
Change the size of the stream queue. Note that the new size can smaller than the current stream queue size.
size < 0.
Number of elements in the stream queue.
Is the stream closed ?
Set the reference to an external source.
Type of sources for bounded push-streams.
create_bounded size returns a new stream and a bounded push
source. The stream can hold a maximum of
size elements. When
this limit is reached, pushing a new element will block until
one is consumed.
Note that you cannot clone or parse (with parse) a bounded
stream. These functions will raise
Invalid_argument if you try
to do so.
size < 0.
clone st clone the given stream. Operations on each stream
will not affect the other.
# let st1 = Lwt_stream.of_list [1; 2; 3];; val st1 : int Lwt_stream.t = <abstr> # let st2 = Lwt_stream.clone st1;; val st2 : int Lwt_stream.t = <abstr> # lwt x = Lwt_stream.next st1;; val x : int = 1 # lwt y = Lwt_stream.next st2;; val y : int = 1
st is a bounded
Exception raised when trying to retreive data from an empty stream.
get_available st returns all available elements of
get_available_up_to n st returns up to
n elements of
Note: all the following functions are destructive.
# let st1 = Lwt_stream.of_list [1; 2; 3];; val st1 : int Lwt_stream.t = <abstr> # let st2 = Lwt_stream.map string_of_int st1;; val st2 : string Lwt_stream.t = <abstr> # lwt x = Lwt_stream.next st1;; val x : int = 1 # lwt y = Lwt_stream.next st2;; val y : string = "2"