CoroutineContext and ContinuationInterceptor (instead of dispatcher)
This commit is contained in:
committed by
Denis Zharkov
parent
f611e39a69
commit
8d6a913cee
@@ -34,6 +34,8 @@ class AsyncGeneratorIterator<T>: AsyncIterator<T>, AsyncGenerator<T>, Continuati
|
||||
var computesNext = false
|
||||
var computeContinuation: Continuation<*>? = null
|
||||
|
||||
override val context = EmptyContext
|
||||
|
||||
suspend fun computeHasNext(): Boolean = suspendCoroutineOrReturn { c ->
|
||||
computesNext = false
|
||||
computeContinuation = c
|
||||
|
||||
@@ -9,6 +9,8 @@ fun builder(c: suspend () -> Unit) {
|
||||
var exception: Throwable? = null
|
||||
|
||||
c.createCoroutine(object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(data: Unit) {
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ class Controller {
|
||||
fun builder(c: suspend Controller.() -> Unit): String {
|
||||
val controller = Controller()
|
||||
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(data: Unit) {
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -17,6 +17,8 @@ class Controller {
|
||||
fun builder(c: suspend Controller.() -> Unit): String {
|
||||
val controller = Controller()
|
||||
c.startCoroutine(controller, object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(data: Unit) {}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class Controller {
|
||||
|
||||
fun test(c: suspend Controller.() -> Unit): String {
|
||||
val controller = Controller()
|
||||
c.startCoroutine(controller, EmptyContinuation, object: ContinuationDispatcher {
|
||||
c.startCoroutine(controller, EmptyContinuation(object: ContinuationDispatcher() {
|
||||
private fun dispatchResume(block: () -> Unit) {
|
||||
val id = controller.resumeIndex++
|
||||
controller.log += "before $id;"
|
||||
@@ -44,7 +44,7 @@ fun test(c: suspend Controller.() -> Unit): String {
|
||||
}
|
||||
return true
|
||||
}
|
||||
})
|
||||
}))
|
||||
return controller.log
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ class GeneratedSequence<out T>(private val block: suspend Generator<T>.() -> Uni
|
||||
|
||||
class GeneratedIterator<T>(block: suspend Generator<T>.() -> Unit) : AbstractIterator<T>(), Generator<T> {
|
||||
private var nextStep: Continuation<Unit> = block.createCoroutine(this, object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(data: Unit) {
|
||||
done()
|
||||
}
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ var result = ""
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
override fun resume(value: Unit) {
|
||||
}
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
|
||||
@@ -12,6 +12,8 @@ fun builder(c: suspend () -> Int): Int {
|
||||
var res = 0
|
||||
|
||||
c.createCoroutine(object : Continuation<Int> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(data: Int) {
|
||||
res = data
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ class Controller {
|
||||
|
||||
fun test(c: suspend Controller.() -> Unit): String {
|
||||
val controller = Controller()
|
||||
c.startCoroutine(controller, EmptyContinuation, object: ContinuationDispatcher {
|
||||
c.startCoroutine(controller, EmptyContinuation(object: ContinuationDispatcher() {
|
||||
private fun dispatchResume(block: () -> Unit) {
|
||||
val id = controller.resumeIndex++
|
||||
controller.log += "before $id;"
|
||||
@@ -44,7 +44,7 @@ fun test(c: suspend Controller.() -> Unit): String {
|
||||
}
|
||||
return true
|
||||
}
|
||||
})
|
||||
}))
|
||||
return controller.log
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -11,6 +11,8 @@ suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
var wasResumeCalled = false
|
||||
c.startCoroutine(object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(value: Unit) {
|
||||
wasResumeCalled = true
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
var wasResumeCalled = false
|
||||
c.startCoroutine(object : Continuation<Unit> {
|
||||
override val context = EmptyContext
|
||||
|
||||
override fun resume(value: Unit) {
|
||||
wasResumeCalled = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user