Periodik
Periodik is a read-only property delegate that can provide a value updated periodically.
A quick example that gets and logs a new value every 2 seconds:
import dev.akif.periodik
import dev.akif.periodik.Schedule
val message by periodik<String>(Schedule.every(2.seconds)).build { previous ->
val newValue = if (previous == null) {
"Hello world!"
} else {
"Hello again on ${System.currentTimeMillis()}!"
}
this.log(newValue)
newValue
}
Parameters
type of the property
Schedule with which to update the value
function to use for getting the current Instant
function to use for adjusting the Instants before using them in time calculations
CoroutineDispatcher to use for blocking coroutines when needed
function to use for waiting for a given kotlin.time.Duration
function to use for logging debug messages
function to use for logging messages
function to use for logging error messages and throwing an Exception
whether to initialize the property eagerly or lazily
function to use for getting the next value with the last known value as function input so that it can be used in calculation of the next value