package async_unix

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Functions that write elements to the pipe take an If_closed.t argument to specify how to deal with the possibility that the pipe is closed: Raise on closed pipe, or Return a variant indicating whether the pipe is closed. This allows lightweight syntax for calls that want to raise if the pipe is closed:

write t a ~if_closed:Raise 

It also allows lightweight syntax for calls that want to match on whether the pipe was closed:

match write t a ~if_closed:Return with
| Closed  -> ...
| Written -> ... 

Returning a variant is essential when one wants to distinguish a closed pipe from other errors. Also, since pipe-writing functions acquire the Async lock, it would be incorrect (due to races) to check is_closed prior to the lock acquisition.

type 'a t =
  1. | Raise : unit t
  2. | Return : Written_or_closed.t t
OCaml

Innovation. Community. Security.