Module Lwt_react.E
module E : sig..end
include React.E
Lwt-specific utilities ¶
val with_finaliser :
(unit -> unit) -> 'a Lwt_react.event -> 'a Lwt_react.event
with_finaliser f e returns an event e' which behave as e, except that f is called when e' is garbage collected.
val next : 'a Lwt_react.event -> 'a Lwt.t
next e returns the next occurrence of e.
Avoid trying to create an "asynchronous loop" by calling next e again in a callback attached to the promise returned by next e:
- The callback is called within the React update step, so calling next e within it will return a promise that is fulfilled with the same value as the current occurrence.
- If you instead arrange for the React update step to end (for example, by calling Lwt.pause () within the callback), multiple React update steps may occur before the callback calls next e again, so some occurrences can be effectively "lost."
To robustly asynchronously process occurrences of e in a loop, use to_stream e, and repeatedly call Lwt_stream.next on the resulting stream.
val limit :
(unit -> unit Lwt.t) -> 'a Lwt_react.event -> 'a Lwt_react.event
limit f e limits the rate of e with f.
For example, to limit the rate of an event to 1 per second you can use: limit (fun () -> Lwt_unix.sleep 1.0) event.
val from : (unit -> 'a Lwt.t) -> 'a Lwt_react.event
from f creates an event which occurs each time f () returns a value. If f raises an exception, the event is just stopped.
val to_stream : 'a Lwt_react.event -> 'a Lwt_stream.t
Creates a stream holding all values occurring on the given event
val of_stream : 'a Lwt_stream.t -> 'a Lwt_react.event
of_stream stream creates an event which occurs each time a value is available on the stream.
val delay : 'a Lwt_react.event Lwt.t -> 'a Lwt_react.event
delay promise is an event which does not occur until promise resolves. Then it behaves as the event returned by promise.
val keep : 'a Lwt_react.event -> unit
keep e keeps a reference to e so it will never be garbage collected.
Threaded versions of React transformation functions ¶
The following functions behave as their React counterpart, except that they take functions that may yield.
As usual the _s suffix is used when calls are serialized, and the _p suffix is used when they are not.
Note that *_p functions may not preserve event order.
val app_s :
('a -> 'b Lwt.t) Lwt_react.event ->
'a Lwt_react.event -> 'b Lwt_react.event
val app_p :
('a -> 'b Lwt.t) Lwt_react.event ->
'a Lwt_react.event -> 'b Lwt_react.event
val map_s : ('a -> 'b Lwt.t) -> 'a Lwt_react.event -> 'b Lwt_react.event
val map_p : ('a -> 'b Lwt.t) -> 'a Lwt_react.event -> 'b Lwt_react.event
val filter_s :
('a -> bool Lwt.t) -> 'a Lwt_react.event -> 'a Lwt_react.event
val filter_p :
('a -> bool Lwt.t) -> 'a Lwt_react.event -> 'a Lwt_react.event
val fmap_s :
('a -> 'b option Lwt.t) -> 'a Lwt_react.event -> 'b Lwt_react.event
val fmap_p :
('a -> 'b option Lwt.t) -> 'a Lwt_react.event -> 'b Lwt_react.event
val diff_s :
('a -> 'a -> 'b Lwt.t) -> 'a Lwt_react.event -> 'b Lwt_react.event
val accum_s : ('a -> 'a Lwt.t) Lwt_react.event -> 'a -> 'a Lwt_react.event
val fold_s :
('a -> 'b -> 'a Lwt.t) ->
'a -> 'b Lwt_react.event -> 'a Lwt_react.event
val merge_s :
('a -> 'b -> 'a Lwt.t) ->
'a -> 'b Lwt_react.event list -> 'a Lwt_react.event
val run_s : 'a Lwt.t Lwt_react.event -> 'a Lwt_react.event
val run_p : 'a Lwt.t Lwt_react.event -> 'a Lwt_react.event