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

type of the property

schedule

Schedule with which to update the value

currentInstant

function to use for getting the current Instant

adjustment

function to use for adjusting the Instants before using them in time calculations

dispatcher

CoroutineDispatcher to use for blocking coroutines when needed

wait

function to use for waiting for a given kotlin.time.Duration

debug

function to use for logging debug messages

log

function to use for logging messages

error

function to use for logging error messages and throwing an Exception

deferInitialization

whether to initialize the property eagerly or lazily

nextValue

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

See also

dev.akif.periodik

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val dispatcher: CoroutineDispatcher
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val wait: suspend Periodik<Type>.(Duration) -> Unit

Functions

Link copied to clipboard
open operator override fun getValue(thisRef: Any, property: KProperty<*>): Type
Link copied to clipboard
open override fun toString(): String