ResourceRefresher

A utility class to repeatedly fetch some resource

The ResourceRefresher.Parameters can be used to configure where to fetch the resource from and how often, as well as some cooldown behaviour in the event of any failures.

Types

Link copied to clipboard
data class Parameters(val id: String, val url: URL, val refreshInterval: TimeFrame, val errorCooldownBaseInterval: TimeFrame? = null)

Parameters explicitly relating to the behavior of the ResourceRefresher.

Properties

Link copied to clipboard
abstract val cache: ResourceCache<T>

The ResourceCache for storing the results and possible etags in.

Link copied to clipboard

An observable stream of exceptions that occur when fetching or reading/writing from storage.

Link copied to clipboard
abstract val resource: Observable<T>

An observable stream of valid resources.

Link copied to clipboard
abstract val shouldRefresh: Boolean

Returns whether or not this resource should be refreshed according to all relevant timeouts and error cooldowns.

Functions

Link copied to clipboard
abstract fun requestRefresh()

Requests that a new refresh of the resource take place. No validation is done on the object that is retrieved.

abstract fun requestRefresh(isValid: (T) -> Boolean)

Requests that a new refresh of the resource take place. The resulting object is passed to the isValid predicate to determine whether or not this should be considered a successful retrieval.

Link copied to clipboard
abstract fun setRefreshInterval(interval: TimeFrame)

Updates the refresh interval for this resource.