Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation improvements: Lwt_main.run and Lwt_io.wait_read/wait_write #547

Merged
merged 6 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/unix/lwt_main.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,26 @@
(** This module controls the ``main-loop'' of Lwt. *)

val run : 'a Lwt.t -> 'a
(** [run t] calls the Lwt scheduler repeatedly until [t] terminates,
then returns the value returned by the thread. If [t] fails with
an exception, this exception is raised.
(** [run p] calls the Lwt scheduler repeatedly until [p] resolves,
and returns the value of [p] if it is fulfilled. If [p] is rejected with
an exception, that exception is raised.

Every native or bytecode program that uses Lwt should always use
this function for evaluating a promise at the top level
(such as its main function or main loop),
otherwise promises that depend on I/O operations will not be resolved.

Example:
{[
let main () = Lwt_io.write_line Lwt_io.stdout "hello world"

let () = Lwt_main.run @@ main ()
]}

When targeting JavaScript, [Lwt_main.run] is not available,
but neither it's necessary since
the JS environment automatically takes care of the I/O considerations.


Note that you should avoid using [run] inside threads
- The calling threads will not resume before [run]
Expand Down
23 changes: 19 additions & 4 deletions src/unix/lwt_unix.cppo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,27 @@ val writable : file_descr -> bool
writable. *)

val wait_read : file_descr -> unit Lwt.t
(** waits (without blocking other threads) until there is something
to read on the file descriptor *)
(** Waits (without blocking other threads) until there is something
to read from the file descriptor.

Note that you don't need to use this function if you are
using Lwt I/O functions for reading, since they provide
non-blocking waiting automatically.

The intended use case for this function is interfacing with
existing libraries that are known to be blocking. *)

val wait_write : file_descr -> unit Lwt.t
(** waits (without blocking other threads) until it is possible to
write on the file descriptor *)
(** Waits (without blocking other threads) until it is possible to
write on the file descriptor.

Note that you don't need to use this function if you are
using Lwt I/O functions for writing, since they provide
non-blocking waiting automatically.

The intended use case for this function is interfacing with
existing libraries that are known to be blocking. *)


(** {2 Seeking and truncating} *)

Expand Down