package lwt

  1. Overview
  2. Docs
Promises and event-driven I/O

Install

Dune Dependency

Authors

Maintainers

Sources

5.4.0.zip
md5=fc4721bdb1a01225b96e3a2debde95fa
sha512=e427f08223b77f9af696c9e6f90ff68e27e02e446910ef90d3da542e7b00bf23dd191ac77c1871288faa2289f8d28fc2f44efc3d3fe9165fe1c7a6be88ee49ff

doc/lwt/Lwt_result/index.html

Module Lwt_resultSource

Explicit error handling

  • since 2.6.0

This module provides helpers for values of type ('a, 'b) result Lwt.t. The module is experimental and may change in the future.

Sourcetype (+'a, +'b) t = ('a, 'b) Result.result Lwt.t
Sourceval return : 'a -> ('a, _) t
Sourceval fail : 'b -> (_, 'b) t
Sourceval lift : ('a, 'b) Result.result -> ('a, 'b) t
Sourceval ok : 'a Lwt.t -> ('a, _) t
Sourceval catch : 'a Lwt.t -> ('a, exn) t

catch x behaves like return y if x evaluates to y, and like fail e if x raises e

Sourceval get_exn : ('a, exn) t -> 'a Lwt.t

get_exn is the opposite of catch: it unwraps the result type, returning the value in case of success, calls Lwt.fail in case of error.

Sourceval map : ('a -> 'b) -> ('a, 'e) t -> ('b, 'e) t
Sourceval map_err : ('e1 -> 'e2) -> ('a, 'e1) t -> ('a, 'e2) t
Sourceval bind : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
Sourceval bind_lwt : ('a, 'e) t -> ('a -> 'b Lwt.t) -> ('b, 'e) t
Sourceval bind_lwt_err : ('a, 'e1) t -> ('e1 -> 'e2 Lwt.t) -> ('a, 'e2) t
Sourceval bind_result : ('a, 'e) t -> ('a -> ('b, 'e) Result.result) -> ('b, 'e) t
Sourceval both : ('a, 'e) t -> ('b, 'e) t -> ('a * 'b, 'e) t

Lwt.both p_1 p_2 returns a promise that is pending until both promises p_1 and p_2 become resolved. If only p_1 is Error e, the promise is resolved with Error e, If only p_2 is Error e, the promise is resolved with Error e, If both p_1 and p_2 resolve with Error _, the promise is resolved with the error that occurred first.

Sourcemodule Infix : sig ... end
Sourcemodule Let_syntax : sig ... end
Sourcemodule Syntax : sig ... end
include module type of Infix
Sourceval (>|=) : ('a, 'e) t -> ('a -> 'b) -> ('b, 'e) t
Sourceval (>>=) : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
OCaml

Innovation. Community. Security.