Beta
Subscribes a callback to receive updates from the poller.
When the first subscriber registers, the poller automatically starts polling. Any new subscriber immediately receives the latest cached value, and all subscribers are notified of subsequent polling results.
A function to unsubscribe from the poller.
A function that will be called with the latest value
from the poller callback. If no value is available, the callback will
receive undefined
.
Optional
value: TSubscribes a callback to receive updates from the poller.
When the first subscriber registers, the poller automatically starts polling. Any new subscriber immediately receives the latest cached value, and all subscribers are notified of subsequent polling results.
A function to unsubscribe from the poller.
A generic interface for a poller that periodically executes a callback and notifies subscribers of the result. The poller manages its lifecycle automatically, ensuring that polling starts when the first subscriber registers and stops when the last subscriber unsubscribes.
The poller caches the most recent value from the callback and immediately delivers it to any new subscriber without waiting for the next polling cycle. This ensures that subscribers always receive the latest available data as soon as they register.
Consumers are only concerned with subscribing to updates. The poller implementation handles polling intervals, error management, and subscriber lifecycle internally, making it simple and reliable for end users.
Example