From ea07b9685836c9231230ec1c728cea0c8eef5958 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Fri, 27 Mar 2020 10:38:21 +0100 Subject: Fix awaitFirst (crashes when inlined) --- .../sevenwonders/ui/utils/CoroutineUtilsTest.kt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 sw-ui-kt/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt (limited to 'sw-ui-kt/src/test/kotlin') diff --git a/sw-ui-kt/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt b/sw-ui-kt/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt new file mode 100644 index 00000000..d633f6f2 --- /dev/null +++ b/sw-ui-kt/src/test/kotlin/org/luxons/sevenwonders/ui/utils/CoroutineUtilsTest.kt @@ -0,0 +1,24 @@ +package org.luxons.sevenwonders.ui.utils + +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.promise +import kotlin.test.Test +import kotlin.test.assertEquals + +class CoroutineUtilsTest { + + @Test + fun awaitFirstTest(): dynamic = GlobalScope.promise { + val s = awaitFirst( + { delay(100); "1" }, + { delay(200); "2" } + ) + assertEquals("1", s) + val s2 = awaitFirst( + { delay(150); "1" }, + { delay(50); "2" } + ) + assertEquals("2", s2) + } +} -- cgit