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

sample f event signal

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

accum ?eq event_f initial

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

fold ?eq f initial event

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

merge ?eq f initial signals

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

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

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

val l4_s :
   ?eq:('a -> 'a -> bool) ->
    ('b -> 'c -> 'd -> 'e -> 'a Lwt.t) ->
    'a ->
    'b React.signal ->
    'c React.signal -> 'd React.signal -> 'e React.signal -> 'a React.signal

val l5_s :
   ?eq:('a -> 'a -> bool) ->
    ('b -> 'c -> 'd -> 'e -> 'f -> 'a Lwt.t) ->
    'a ->
    'b React.signal ->
    'c React.signal ->
    'd React.signal -> 'e React.signal -> 'f React.signal -> 'a React.signal

val l6_s :
   ?eq:('a -> 'a -> bool) ->
    ('b -> 'c -> 'd -> 'e -> 'f -> 'g -> 'a Lwt.t) ->
    'a ->
    'b React.signal ->
    'c React.signal ->
    'd React.signal ->
    'e React.signal -> 'f React.signal -> 'g React.signal -> 'a React.signal

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


Notification


type notifier

Type of signal notifiers

val disable : notifier -> unit

disable notif stops the corresponding signal to be monitored

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

notify f s calls f each time the value of s change

val notify_p : ('a -> unit Lwt.t) -> 'a React.signal -> notifier

notify_p f s is the same as notify except that f x is a thread. Calls to f are made in parallel.

val notify_s : ('a -> unit Lwt.t) -> 'a React.signal -> notifier

notify_s f s is the same as notify except that f x is a thread. Calls to f are serialized.

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

Same as notify but does not return a notifier

val always_notify_p : ('a -> unit Lwt.t) -> 'a React.signal -> unit

Same as notify_p but does not return a notifier

val always_notify_s : ('a -> unit Lwt.t) -> 'a React.signal -> unit

Same as notify_s but does not return a notifier