Picos_std_sync.Stream
A lock-free, poisonable, many-to-many, stream.
Readers can tap
into a stream to get a cursor
for reading all the values pushed to the stream starting from the cursor
position. Conversely, values pushed to a stream are lost unless a reader has a cursor
to the position in the stream.
val create : ?padded:bool -> unit -> 'a t
create ()
returns a new stream.
val push : 'a t -> 'a -> unit
val poison_at : 'a t -> exn -> Stdlib.Printexc.raw_backtrace -> unit
poison_at stream exn bt
marks the stream as poisoned at the current position, which means that subsequent attempts to push
to the stream
will raise the given exception with backtrace.
âšī¸ This operation is not cancelable.
val poison : ?callstack:int -> 'a t -> exn -> unit
poison stream exn
is equivalent to poison_at stream exn (Printexc.get_callstack n)
where n
defaults to 0
.
peek_opt cursor
immediately returns Some (value, next)
with the value
pushed to the position and a cursor to the next
position, when the cursor
points to a past position in the stream. Otherwise returns None
or raises the exception that the stream was poisoned with.
read cursor
immediately returns (value, next)
with the value
pushed to the position and a cursor to the next
position, when the cursor
points to a past position in the stream. If the cursor
points to the current position of the stream, read cursor
waits until a value is pushed to the stream or the stream is poisoned, in which case the exception that the stream was poisoned with will be raised.
val read_evt : 'a cursor -> ('a * 'a cursor) Picos_std_event.Event.t
read_evt cursor
returns an event that reads from the cursor
position.