Ratatouille v0.5.1 Ratatouille.Runtime.Subscription View Source

Subscriptions provide a way for the app to be notified via Ratatouille.App.update/2 when something interesting happens.

Subscriptions should be constructed via the functions below and not via the struct directly, as this is internal and subject to change.

Currently, it's possible to subscribe to time intervals (interval/2) and to create batch subscriptions (i.e., multiple time intervals). More subscription types may be introduced later.

Accuracy of Time Intervals

Ratatouille's runtime loop, which handles subscriptions, runs on a interval itself (by default, every 500 ms). This means that the runtime loop is the minimum possible subscription interval. If a subscription's interval is more frequent than the runtime loop interval, the runtime loop interval is the subscription's effective interval.

There is also no guarantee that subscriptions will be processed on time, as the runtime may be busy with other tasks (e.g., handling events or rendering). With that said, if care is taken to keep expensive calls out of the runtime loop, subscriptions should be processed very close to requested interval.

Link to this section Summary

Functions

Creates a batch subscription from a list of subscriptions.

Returns a subscription based on a time interval. Takes the number of milliseconds (ms) and a message as arguments. When returned in the Ratatouille.App.subscribe/1 callback, the runtime will call the Ratatouille.App.update/2 function with current model and the message, on approximately the given interval. See above for details on what "approximately" means here.

Link to this section Types

Link to this section Functions

Link to this function

batch(subs)

View Source
batch([t()]) :: t()

Creates a batch subscription from a list of subscriptions.

This provides a way to subscribe to multiple things, while still returning a single subscription in Ratatouille.App.subscribe/1.

Link to this function

interval(ms, message)

View Source
interval(non_neg_integer(), term()) :: t()

Returns a subscription based on a time interval. Takes the number of milliseconds (ms) and a message as arguments. When returned in the Ratatouille.App.subscribe/1 callback, the runtime will call the Ratatouille.App.update/2 function with current model and the message, on approximately the given interval. See above for details on what "approximately" means here.