Minor. Simplify 'async' tests
This commit is contained in:
+4
-13
@@ -12,10 +12,8 @@ fun foobar(x: String, y: String) = x + y
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
var result = ""
|
var result = ""
|
||||||
fun log(x: String) {
|
fun log(x: String) {
|
||||||
synchronized(result) {
|
if (result.isNotEmpty()) result += "\n"
|
||||||
if (result.isNotEmpty()) result += "\n"
|
result += x
|
||||||
result += x
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val future = async<String> {
|
val future = async<String> {
|
||||||
@@ -29,14 +27,7 @@ fun box(): String {
|
|||||||
|
|
||||||
future.whenComplete { value, t ->
|
future.whenComplete { value, t ->
|
||||||
log("completed with '$value'")
|
log("completed with '$value'")
|
||||||
}
|
}.join()
|
||||||
|
|
||||||
future.join()
|
|
||||||
java.lang.Thread.sleep(1000)
|
|
||||||
|
|
||||||
val readResult = synchronized(result) {
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
val expectedResult =
|
val expectedResult =
|
||||||
"""
|
"""
|
||||||
@@ -45,7 +36,7 @@ fun box(): String {
|
|||||||
|got '123 bar with foo' after 'foo'
|
|got '123 bar with foo' after 'foo'
|
||||||
|completed with '123 bar with foo'""".trimMargin().trim('\n', ' ')
|
|completed with '123 bar with foo'""".trimMargin().trim('\n', ' ')
|
||||||
|
|
||||||
if (expectedResult != readResult) return readResult
|
if (expectedResult != result) return result
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ fun box(): String {
|
|||||||
|
|
||||||
if (future.get() != "56") return "fail: ${future.get()}"
|
if (future.get() != "56") return "fail: ${future.get()}"
|
||||||
|
|
||||||
java.lang.Thread.sleep(1000)
|
|
||||||
|
|
||||||
if (result != "OK") return "fail notOk"
|
if (result != "OK") return "fail notOk"
|
||||||
|
|
||||||
val future2 = async<String>() {
|
val future2 = async<String>() {
|
||||||
|
|||||||
Reference in New Issue
Block a user