package lwt-pipe
Install
Dune Dependency
Authors
Maintainers
Sources
md5=46cfc88c4220d40356f6bea7c535be6e
sha512=ebc04adf58d913aac8caf43d76b2191fa76101c60a48f6c992a396e5bc8b0756d1c6ca0f9038141b77a40185c8cdb03a9de62252b1d23b06e12f201a9dff914b
doc/lwt-pipe/Lwt_pipe/index.html
Module Lwt_pipe
Source
Pipes, Readers, Writers
Stream processing using:
- Pipe: a possibly buffered channel that can act as a reader or as a writer
- Reader: accepts values, produces effects
- Writer: yield values
Examples:
#require "lwt";;
module P = Lwt_pipe;;
let p1 =
P.of_list CCList.(1 -- 100)
|> P.Reader.map ~f:string_of_int;;
Lwt_io.with_file ~mode:Lwt_io.output "/tmp/foo"
(fun oc ->
let p2 = P.IO.write_lines oc in
P.connect ~ownership:`InOwnsOut p1 p2;
P.wait p2
);;
status: experimental
A pipe between producers of values of type 'a, and consumers of values of type 'a.
keep p fut
adds a pointer from p
to fut
so that fut
is not garbage-collected before p
close p
closes p
, which will not accept input anymore. This sends End
to all readers connected to p
Same as close
but does not wait for completion of dependent tasks
Create a new pipe.
val connect :
?ownership:[ `None | `InOwnsOut | `OutOwnsIn ] ->
('a, [> `r ]) t ->
('a, [> `w ]) t ->
unit
connect p1 p2
forwards every item output by p1
into p2
's input until p1
is closed.
link_close p ~after
will close p
when after
closes. if after
is closed already, closes p
immediately
val read_with_timeout :
('a, [> `r ]) t ->
timeout:float option ->
'a read_timeout_result Lwt.t
read_with_timeout p ~timeout
read the next value from a Pipe, optionally waiting for at most a number of seconds passed with the timeout
parameter.
to_stream p
returns a stream with the content from p
. The stream will close when p
closes.
of_stream s
reads from s
. The returned pipe will close when s
closes.
Write-only Interface and Combinators
Read-only Interface and Combinators
Conversions
Iterates on the reader. Errors are ignored (but stop the list).