Module Lwt_signal

module Lwt_signal: sig..end

Signals utilities

Monadic interface

val return : 'a -> 'a React.signal

Same as React.S.const

val bind : 'a React.signal -> ('a -> 'b React.signal) -> 'b React.signal

bind signal f is initially f x where x is the current value of signal. Each time signal changes to a new value y, bind signal f is set to f y, until the next change of signal.

Lwt-specific utilities

val with_finaliser : (unit -> unit) -> 'a React.signal -> 'a React.signal

with_finaliser f signal returns a signal signal' which behave as signal, except that f is called when signal' is garbage collected.

val limit :
   ?eq:('a -> 'a -> bool) ->
    (unit -> unit Lwt.t) -> 'a React.signal -> 'a React.signal

limit f signal limits the rate of signal update with f.

For example, to limit it to 1 per second, you can use: limit (fun () -> Lwt_unix.sleep 1.0) signal.

val delay : 'a React.signal Lwt.t -> 'a React.event

delay thread is an event which does not occurs until thread returns. When thread returns a signal s, delay thread will occurs with the current value of s, and then behaves as React.S.changes s.

Threaded versions of React transformation functions

The following functions behave as their React counterpart, except that they takes functions that may yield. Also, since signals must always have a value, several functions takes an extra argument for the initial value.

The _s suffix means that calls are serialized.

val app_s :
   ?eq:('a -> 'a -> bool) ->
    ('b -> 'a Lwt.t) React.signal -> 'a -> 'b React.signal -> 'a React.signal

app_s ?eq signal_f initial signal_x

val map_s :
   ?eq:('a -> 'a -> bool) ->
    ('b -> 'a Lwt.t) -> 'a -> 'b React.signal -> 'a React.signal

map_s ?eq f initial signal

val filter_s :
   ?eq:('a -> 'a -> bool) ->
    ('a -> bool Lwt.t) -> 'a -> 'a React.signal -> 'a React.signal

filter_s ?eq f initial signal

val fmap_s :
   ?eq:('a -> 'a -> bool) ->
    ('b -> 'a option Lwt.t) -> 'a -> 'b React.signal -> 'a React.signal

fmap ?eq f initial signal

val diff_s : ('a -> 'a -> 'b Lwt.t) -> 'a React.signal -> 'b React.event

diff_s f signal

val sample_s : ('a -> 'b -> 'c Lwt.t) -> 'a React.event -> 'b React.signal -> 'c React.event