Module Thread_safe_pipe

module Thread_safe_pipe: sig .. end
A thread-safe pipe is a thread-safe interface to the write end of a normal Async.Pipe. All operations except for create must be called from threads outside async. create can be called from inside or outside async.

For Pipe functions that return a unit Deferred.t, the analog in Thread_safe_pipe blocks.

For documentation of wakeup_scheduler, see the Thread_safe module.


type 'a t 
val create : unit -> 'a Import.Pipe.Reader.t * 'a t
create () returns a reader end, which must be used inside async, and a writer end, which must be used outside async. create can be called inside or outside async.

All the following functions must be called outside async. They behave as their counterpart in the Pipe module.
val pushback : 'a t -> unit
pushback writer blocks the current thread until the pipe is empty or closed.
val write_without_pushback' : ?wakeup_scheduler:bool ->
'a t -> 'a Core.Std.Queue.t -> unit
write_without_pushback' and write_without_pushback transfer the element(s) into the pipe and return immediately.
val write_without_pushback : ?wakeup_scheduler:bool -> 'a t -> 'a -> unit
val write' : 'a t -> 'a Core.Std.Queue.t -> unit
write' and write transfer the element(s) into the pipe and block the current thread until the pipe is empty or closed (like Thread_safe_pipe.pushback).
val write : 'a t -> 'a -> unit
val close : 'a t -> unit
val is_closed : 'a t -> bool
val closed : 'a t -> unit
closed writer blocks the current thread until the pipe is closed.
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> 'a t -> Sexplib.Sexp.t

create () returns a reader end, which must be used inside async, and a writer end, which must be used outside async. create can be called inside or outside async.

All the following functions must be called outside async. They behave as their counterpart in the Pipe module.

pushback writer blocks the current thread until the pipe is empty or closed.

write_without_pushback' and write_without_pushback transfer the element(s) into the pipe and return immediately.

write' and write transfer the element(s) into the pipe and block the current thread until the pipe is empty or closed (like Thread_safe_pipe.pushback).

closed writer blocks the current thread until the pipe is closed.