Event loop and continuations interfaces
This commit is contained in:
parent
0f74f7f4e3
commit
01ae67c212
@ -54,7 +54,11 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting
|
val commonMain by getting {
|
||||||
|
dependencies {
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib:${this@kotlin.coreLibrariesVersion}")
|
||||||
|
}
|
||||||
|
}
|
||||||
val commonTest by getting
|
val commonTest by getting
|
||||||
|
|
||||||
val notJvmMain by creating { dependsOn(commonMain) }
|
val notJvmMain by creating { dependsOn(commonMain) }
|
||||||
@ -88,8 +92,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
package ru.landgrafhomyak.multitasking_0
|
||||||
|
|
||||||
|
public fun interface CancellationHandler {
|
||||||
|
public fun onCancellation(): Throwable
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package ru.landgrafhomyak.multitasking_0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback that resumes execution of a corresponding task [at suspension point][SingleThreadEventLoop.yield].
|
||||||
|
*/
|
||||||
|
public interface Continuation<T> {
|
||||||
|
/**
|
||||||
|
* Resumes task with result that will be returned from [yield()][SingleThreadEventLoop.yield].
|
||||||
|
*/
|
||||||
|
public fun resumeWithSuccess(result: T)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resumes task with error that will be thrown from [yield()][SingleThreadEventLoop.yield].
|
||||||
|
*/
|
||||||
|
public fun resumeWithError(result: Throwable)
|
||||||
|
|
||||||
|
|
||||||
|
public interface Cancellable<T> : Continuation<T> {
|
||||||
|
/**
|
||||||
|
* Set's callback called when task is canceled, but not earlier than [linkContinuation()][ContinuationHandler.linkContinuation] returns.
|
||||||
|
*/
|
||||||
|
public fun setCancellationHandler(handler: CancellationHandler)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package ru.landgrafhomyak.multitasking_0
|
||||||
|
|
||||||
|
public fun interface ContinuationHandler<R, C : Continuation<R>> {
|
||||||
|
public fun linkContinuation(continuation: C)
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package ru.landgrafhomyak.multitasking_0
|
||||||
|
|
||||||
|
public interface SingleThreadEventLoop {
|
||||||
|
public fun callAfter(delayMillis: Long, continuation: Continuation<Unit>)
|
||||||
|
|
||||||
|
public fun <R> yield(handler: ContinuationHandler<R, Continuation<R>>): R
|
||||||
|
public fun <R> yieldCancellable(handler: ContinuationHandler<R, Continuation.Cancellable<R>>): R
|
||||||
|
|
||||||
|
public fun runUntilSuspended()
|
||||||
|
public fun suspendEventLoop()
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package ru.landgrafhomyak.multitasking_0
|
||||||
|
|
||||||
|
import kotlin.RuntimeException
|
||||||
|
|
||||||
|
public class TaskCancelledException : RuntimeException {
|
||||||
|
public constructor() : super()
|
||||||
|
public constructor(message: String?) : super(message)
|
||||||
|
public constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||||
|
public constructor(cause: Throwable?) : super(cause)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user