package tube
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=58d5a8775d6ccd2752d4fdacb12be8f86c4efa769c4755cc05b43782f31efefd
md5=65e17606d445d517aad1f912daca4d88
Description
A typesafe abstraction on top of Lwt_io channels in order to avoid things like unsafe operations (i.e. https://github.com/ocsigen/lwt/issues/345 ) when running in practice.
Added to opam-repository:
README
Ok, really nothing to see here, some Pipe abstraction on top of Lwt_io channels
Why did I do this thing, and not using directly Lwt_io channels (or even better, Async Pipes)?
Because of things like this https://github.com/ocsigen/lwt/issues/345 Quite easy to do it wrong, so for very basic operations when working with local data, we can use this (I surely am), brings a little bit more of a type safety into all that write/read value to channels.
How to build:
opam install jbuilder core lwt
makeHow to use:
> module Pipe = Tube.Make(struct type t = string end);;
module Pipe :
sig
type t = string
type reader
type writer
val create : unit -> reader * writer
val write : t -> writer -> unit Lwt.t
val read : reader -> t Lwt.t
end
> let (reader, writer) = Pipe.create ();;
val reader : Pipe.reader = <abstr>
val writer : Pipe.writer = <abstr>
> Pipe.write "something" writer;;
- : unit = ()
> Lwt.(Pipe.read reader >>= fun s -> Lwt_io.printlf "My fancy value: %s" s);;
My fancy value: something
- : unit = ()
> Pipe.write 911 writer;;
Error: This expression has type int but an expression was expected of type
stringor, for write with pushback:
> let (reader, writer) = Pipe.create ();;
val reader : Pipe.reader = <abstr>
val writer : Pipe.writer = <abstr>
> Pipe.write_with_pushback "something" writer;;
(* This will block, when using inside of `utop`, till something reads from the created `reader`; *)
(* when doing this write in a different context than `utop`, the produced Lwt.t will not move on *)
(* until something will read from the `reader` *)or, for custom data types:
> type roman_numeral = I | II | III | IV | V | VI | VII | VIII | IX | X;;
type roman_numeral = I | II | III | IV | V | VI | VII | VIII | IX | X
> module Pipe = Tube.Make(struct type t = roman_numeral end);;
module Pipe :
sig
type t = roman_numeral
type reader
type writer
val create : unit -> reader * writer
val write : t -> writer -> unit Lwt.t
val read : reader -> t Lwt.t
end
> let (reader, writer) = Pipe.create ();;
val reader : Pipe.reader = <abstr>
val writer : Pipe.writer = <abstr>
> Pipe.write IX writer;;
- : unit = ()
> Lwt.(Pipe.read reader >>= fun s ->
match s with
| IX -> Lwt_io.printl "9"
| _ -> Lwt_io.printl "Don't care...");;
9
- : unit = ()
> Pipe.write "not cool" writer;;
Error: This expression has type string but an expression was expected of type
roman_numeral
Dev Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building tube with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 4.4.0 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure