Task interface
This commit is contained in:
parent
01ae67c212
commit
a453e53a14
@ -1,6 +1,30 @@
|
||||
package ru.landgrafhomyak.multitasking_0
|
||||
|
||||
public interface SingleThreadEventLoop {
|
||||
/**
|
||||
* Returns thread on which this event loop runs.
|
||||
* Threadsafe getter.
|
||||
*/
|
||||
public val thread: Thread
|
||||
|
||||
/**
|
||||
* Returns `true` if event loop running now.
|
||||
* Threadsafe getter.
|
||||
*
|
||||
* Value `false` means that [runUntilSuspended()][SingleThreadEventLoop.runUntilSuspended] can be called.
|
||||
*/
|
||||
public val isRunning: Boolean
|
||||
|
||||
/**
|
||||
* Adds [task][kernel] to scheduler's queue.
|
||||
* Returns immediately. Threadsafe.
|
||||
*/
|
||||
public fun addTask(kernel: TaskKernel): Task
|
||||
|
||||
/**
|
||||
* Schedules [continuation.resumeWithSuccess(Unit)][Continuation.resumeWithSuccess] to be called after [delayMillis] milliseconds.
|
||||
* Threadsafe.
|
||||
*/
|
||||
public fun callAfter(delayMillis: Long, continuation: Continuation<Unit>)
|
||||
|
||||
public fun <R> yield(handler: ContinuationHandler<R, Continuation<R>>): R
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package ru.landgrafhomyak.multitasking_0
|
||||
|
||||
public interface Task {
|
||||
public val name: String
|
||||
public val eventLoop: SingleThreadEventLoop
|
||||
|
||||
public fun cancel()
|
||||
|
||||
|
||||
public val state: State
|
||||
public val exception: Throwable
|
||||
|
||||
public enum class State {
|
||||
PENDING,
|
||||
RUNNING,
|
||||
WAITING,
|
||||
FINISHED_SUCCESSFULLY,
|
||||
FINISHED_WITH_ERROR
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package ru.landgrafhomyak.multitasking_0
|
||||
|
||||
public fun interface TaskKernel {
|
||||
public fun run(task: Task)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user