|Number of watchers on Github||250|
|Number of open issues||78|
|Average time to close an issue||about 2 months|
|Average time to merge a PR||8 days|
|Open pull requests||33+|
|Closed pull requests||24+|
|Last commit||over 2 years ago|
|Repo Created||about 7 years ago|
|Repo Last Updated||over 2 years ago|
|Organization / Author||ocsigen|
|Do you use lwt? Leave a review!|
|View open issues (78)|
|View lwt activity|
|View on github|
|Book a Mock Interview With Me (Silicon Valley Engineering Leader, 100s of interviews conducted)|
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Lwt is OCaml's concurrent programming library. It provides a single data type: the promise, which is a value that will become determined in the future. Creating a promise spawns a computation. When that computation is I/O, Lwt runs it in parallel with your OCaml code.
OCaml code, including creating and waiting on promises, is run in a single thread by default, so you don't have to worry about locking or preemption. You can detach code to be run in separate threads on an opt-in basis.
Here is a simplistic Lwt program which requests the Google front page, and fails if the request is not completed in five seconds:
let () = let request = let%lwt addresses = Lwt_unix.getaddrinfo "google.com" "80"  in let google = Lwt_unix.((List.hd addresses).ai_addr) in Lwt_io.(with_connection google (fun (incoming, outgoing) -> let%lwt () = write outgoing "GET / HTTP/1.1\r\n" in let%lwt () = write outgoing "Connection: close\r\n\r\n" in let%lwt response = read incoming in Lwt.return (Some response))) in let timeout = let%lwt () = Lwt_unix.sleep 5. in Lwt.return None in match Lwt_main.run (Lwt.pick [request; timeout]) with | Some response -> print_string response | None -> prerr_endline "Request timed out"; exit 1 (* ocamlfind opt -package lwt.unix -package lwt.ppx -linkpkg -o request example.ml ./request *)
In the program, functions such as
Lwt_io.write create promises. The
let%lwt ... in construct is used to wait for a promise to become determined;
the code after
in is scheduled to run in a
promises against each other, and behaves as the first one to complete.
Lwt_main.run forces the whole promise-computation network to be executed. All
the visible OCaml code is run in a single thread, but Lwt internally uses a
combination of worker threads and non-blocking file descriptors to resolve in
parallel the promises that do I/O.
Lwt_unixthat binds almost every Unix system call. A higher-level module
Lwt_ioprovides nice I/O channels.
Lwt_processis for subprocess handling.
Lwt_preemptivespawns system threads.
Lwt_reactfor reactive programming. See the table of contents on the linked manual pages!
opam install conf-libev lwt
We are currently working on improving the Lwt documentation (drastically; we are rewriting the manual). In the meantime:
Note: much of the current manual refers to
'a Lwt.t as
threads. This will be fixed in the new manual.
'a Lwt.t is a
promise, and has nothing to do with system or preemptive threads.
Open an issue, visit Gitter chat, ask in #ocaml, on discuss.ocaml.org, or on Stack Overflow. Please do ask! Even apparently simple questions often end up educating other users, not to mention enlightening the maintainers!
Subscribe to the announcements issue to get news about Lwt releases. It is less noisy than watching the whole repository. Announcements are also made in /r/ocaml, on the OCaml mailing list, and on discuss.ocaml.org.
CONTRIBUTING.mdcontains tips for working on the code, such as how to check the code out, how review works, etc. There is also a high-level outline of the code base.
Lwt is released under the LGPL, with an OpenSSL linking exception. See
alcotest A lightweight framework for unit testing
angstrom A library for building parsers with a focus on efficiency, concurrency, and reusability
cohttp A lightweight library for writing HTTP clients and servers
cstruct A library and syntax extension for interop with C-like structures
ezjsonm A library for easy interop with JSON
faraday A library for fast and memory-efficient serialization
logs A logging library with reporting decoupled from logging
lwt-parallel A library for distributed computing
Lwt_listfunctions are now tail-recursive (#538, Joseph Thomas).
;%lwtsyntax in the PPX (#307, Hezekiah Carty).
Lwt_stream.iter_n(#312, Hezekiah Carty).
Lwt 3.2.1 is released because it still packages
lwt.ppx, a deprecated copy of package
lwt_ppx, and the two packages should be kept in sync.
[%lwt ...]PPX syntax should be replaced by
-helpusage message output (#525, Zan Doye).
Lwt_mvar.is_empty(#459, Hezekiah Carty).
Lwt_io.with_temp_file(#467, Joe Thomas).
Lwt_pool.create(#483, Hezekiah Carty).
Lwt_pool.wait_queue_length(#493, Jerome Vouillon).
Lwt.npicknever worked (#447, Zack Coker).
Lwt_pool.usenow always calls
?validateon elements (#461, Joe Thomas).
pthread_createfails (#493, @koen-struyve).
Lwt_unix.getnameinfo(#503, Hannes Mehnert).
Planned to break in 4.0.0
See #453 for details and instructions about planned breakage in Lwt 4.0.0.
lwt_ppx. This package is installable from opam now, as of Lwt 3.2.0 (#338).
lwt_camlp4, which is installable from opam now (#370).
Lwt_daemonare being deprecated and factored out into opam package
lwt_log, also installable from opam now. Use the logs library for logging, in particular module
Logs_lwt. Direct daemonization is deprecated on most platforms (#484, Hannes Mehnert).
>>construct from the PPX will be deleted (#471, Raphal Proust).
lwt.preemptiveis being merged into
lwt.unix. In 3.2.0,
lwt.preemptivebecomes an alias for
lwt.unix, and the package name
lwt.preemptivewill be deleted in 4.0.0 (#487).
Lwt.waiter_of_wakenershould not be used, as it can lead to soundness bugs in future (but not current) Lwt (#458).
Lwt_sequencewas deprecated in Lwt 2.6.0, but it now has a warning attached, as do
Lwt.add_task_l, which use it (#361).
Lwt_pool(#464, Joe Thomas).