Module Lwt_fmtSource

Format API for Lwt-powered IOs

This module bridges the gap between Stdlib.Format and Lwt. Although it is not required, it is recommended to use this module with the Fmt library.

Compared to regular formatting function, the main difference is that printing statements will now return promises instead of blocking.

Sourceval printf : ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a

Returns a promise that prints on the standard output. Similar to Stdlib.Format.printf.

Sourceval eprintf : ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a

Returns a promise that prints on the standard error. Similar to Stdlib.Format.eprintf.

Formatters

Sourcetype formatter

Lwt enabled formatters

Sourcetype order =
  1. | String of string * int * int
    (*

    String (s, off, len) indicate the output of s at offset off and length len.

    *)
  2. | Flush
    (*

    Flush operation

    *)
Sourceval make_stream : unit -> order Lwt_stream.t * formatter

make_stream () returns a formatter and a stream of all the writing order given on that stream.

of_channel oc creates a formatter that writes to the channel oc.

Sourceval stdout : formatter

Formatter printing on Lwt_io.stdout.

Sourceval stderr : formatter

Formatter printing on Lwt_io.stdout.

Sourceval make_formatter : commit:(unit -> unit Lwt.t) -> fmt:Format.formatter -> unit -> formatter

make_formatter ~commit ~fmt creates a new lwt formatter based on the Stdlib.Format.formatter fmt. The commit function will be called by the printing functions to update the underlying channel.

Sourceval get_formatter : formatter -> Format.formatter

get_formatter fmt returns the underlying Stdlib.Format.formatter. To access the underlying formatter during printing, it is recommended to use %t and %a.

Printing

Sourceval fprintf : formatter -> ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
Sourceval kfprintf : (formatter -> unit Lwt.t -> 'a) -> formatter -> ('b, Format.formatter, unit, 'a) format4 -> 'b
Sourceval ifprintf : formatter -> ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
Sourceval ikfprintf : (formatter -> unit Lwt.t -> 'a) -> formatter -> ('b, Format.formatter, unit, 'a) format4 -> 'b
Sourceval flush : formatter -> unit Lwt.t

flush fmt flushes the formatter (as with Stdlib.Format.pp_print_flush) and executes all the printing action on the underlying channel.

Low level functions

Sourceval write_order : Lwt_io.output_channel -> order -> unit Lwt.t

write_order oc o applies the order o on the channel oc.

Sourceval write_pending : formatter -> unit Lwt.t

Write all the pending orders of a formatter. Warning: This function flush neither the internal format queues nor the underlying channel and is intended for low level use only. You should probably use flush instead.