JS: implement new coroutine convention
This commit is contained in:
committed by
Stanislav Erokhin
parent
9fd1ac72a9
commit
e2d969d8b0
@@ -17,10 +17,10 @@ class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: () -> String): String {
|
||||
fun builder(c: suspend Controller.() -> String): String {
|
||||
val controller = Controller()
|
||||
c.startCoroutine(handleResult {
|
||||
controller.result += "return($value);"
|
||||
c.startCoroutine(controller, handleResultContinuation {
|
||||
controller.result += "return($it);"
|
||||
})
|
||||
return controller.result
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// MODULE: main(controller)
|
||||
// MODULE: main(controller, support)
|
||||
// FILE: main.kt
|
||||
import lib.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
import kotlin.coroutines.*
|
||||
|
||||
|
||||
suspend fun suspendHere(): String = suspendWithCurrentContinuation { x ->
|
||||
x.resume("OK")
|
||||
SUSPENDED
|
||||
|
||||
@@ -602,6 +602,7 @@ public class KotlinTestUtils {
|
||||
|
||||
List<F> testFiles = Lists.newArrayList();
|
||||
Matcher matcher = FILE_OR_MODULE_PATTERN.matcher(expectedText);
|
||||
boolean hasModules = false;
|
||||
if (!matcher.find()) {
|
||||
// One file
|
||||
testFiles.add(factory.createFile(null, testFileName, expectedText, directives));
|
||||
@@ -614,6 +615,7 @@ public class KotlinTestUtils {
|
||||
String moduleName = matcher.group(1);
|
||||
String moduleDependencies = matcher.group(2);
|
||||
if (moduleName != null) {
|
||||
hasModules = true;
|
||||
module = factory.createModule(moduleName, parseDependencies(moduleDependencies));
|
||||
}
|
||||
|
||||
@@ -642,7 +644,8 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
|
||||
testFiles.add(factory.createFile(null,
|
||||
M supportModule = hasModules ? factory.createModule("support", Collections.<String>emptyList()) : null;
|
||||
testFiles.add(factory.createFile(supportModule,
|
||||
"CoroutineUtil.kt",
|
||||
"import kotlin.coroutines.*\n" +
|
||||
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
|
||||
|
||||
Reference in New Issue
Block a user