Task

open class Task(var duration: Duration, val callback: suspend () -> Unit, var pollingSeconds: Long = 1, val coroutineScope: CoroutineScope = dev.kordex.core.utils.getKoin().get<Kord>(), val parent: Scheduler? = null, val name: String = "Unnamed", val repeat: Boolean = false) : KordExKoinComponent

Simple class representing a polling-based delayed task. Coroutine-based.

Parameters

duration

How long to wait until the callback should be executed.

callback

Callback to execute on task completion.

pollingSeconds

How often to check whether enough time has passed - 1 by default.

coroutineScope

Coroutine scope to launch in - Kord's by default.

parent

Parent Scheduler object, if any.

name

Optional task name, "Unnamed" by default.

repeat

Whether the task should repeat after completion. false by default.

Constructors

Link copied to clipboard
constructor(duration: Duration, callback: suspend () -> Unit, pollingSeconds: Long = 1, coroutineScope: CoroutineScope = dev.kordex.core.utils.getKoin().get<Kord>(), parent: Scheduler? = null, name: String = "Unnamed", repeat: Boolean = false)

Properties

Link copied to clipboard

Cache map for storing data for this task, if needed.

Link copied to clipboard
open val callback: suspend () -> Unit
Link copied to clipboard
open val coroutineScope: CoroutineScope
Link copied to clipboard
open var duration: Duration
Link copied to clipboard

Number of times this task has been executed.

Link copied to clipboard
Link copied to clipboard
open val parent: Scheduler? = null
Link copied to clipboard
Link copied to clipboard
val repeat: Boolean = false
Link copied to clipboard

Whether this task is currently running - that is, waiting until it's time to execute the callback.

Functions

Link copied to clipboard
suspend fun callNow()

Stop waiting and immediately execute the callback.

Link copied to clipboard
fun cancel()

Stop waiting and don't execute.

Link copied to clipboard
suspend fun cancelAndJoin()

Like cancel, but blocks ..

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
suspend fun join()

Join the running job, if any.

Link copied to clipboard
suspend fun restart()

If the task is running, cancel it and restart it.

Link copied to clipboard
suspend fun restartJoining()

Like restart, but blocks until the cancellation has been applied.

Link copied to clipboard

Calculate whether it's time to start this task, returning true if so.

Link copied to clipboard
suspend fun start()

Mark the start time and begin waiting until the execution time has been reached.