JS: implementing try/finally in coroutines

This commit is contained in:
Alexey Andreev
2016-11-01 19:22:17 +03:00
parent 23bddac4fe
commit d5a808dff6
3 changed files with 250 additions and 61 deletions
@@ -2,7 +2,7 @@
var globalResult = ""
var wasCalled = false
class Controller {
val postponedActions = java.util.ArrayList<() -> Unit>()
val postponedActions = mutableListOf<() -> Unit>()
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
postponedActions.add {
@@ -71,7 +71,7 @@ fun box(): String {
builder(expectException = true) {
try {
suspendWithException(java.lang.RuntimeException("OK"))
suspendWithException(RuntimeException("OK"))
} finally {
if (suspendWithValue("G") != "G") throw RuntimeException("fail 2")
wasCalled = true