-
Notifications
You must be signed in to change notification settings - Fork 23
Services
The Blue Alliance makes use of several service classes. Services are objects that encapsulate some amount of work and tend to be long-lived in memory. Services will generally respond to some external action and execute accordingly when necessary.
RetryService
is a serviced used (exclusively) by other service classes to manage scheduling logic to be performed periodically. RetryService
manages both the lifecycle and threading considerations for a Timer
object. Only objects that conform to Retryable
are able to be managed by a RetryService
. RetryService
should only be used within other services.
Retryable
objects must must register with their RetryService
via registerRetryable()
to setup a timer and start receiving periodic calls to retry()
. The duration between calls is set by retryInterval
- the time internal in seconds, represented as a Double. RetryService
can fire an initial execution of its Retryable
s retry()
during registration by calling registerRetryable(initiallyRetry: true)
. This is useful for objects that execute a timed task in retry()
to be executed immediately upon registering with their RetryService
, as opposed to the next execution of their scheduled timer.
Keep in mind the lifecycle related to a Timer
when using RetryService
. A Timer
created during registerRetryable()
will hold a strong reference to it's Retryable
object. Failing to call unregisterRetryable()
when a Retryable
is done with it's retry logic will keep the Retryable
and RetryService
objects in memory. Alternatively, if a service is meant to remain in memory for the lifespan of the app, avoid calling unregisterRetryable()
if there are no other strong references to the object.
You can read more about Timer
lifecycles from Apple's Using Timers documentation