File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed
ui/kotlinx-coroutines-javafx/src
main/kotlin/kotlinx/coroutines/experimental/javafx
test/kotlin/kotlinx/coroutines/experimental/javafx Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -30,14 +30,13 @@ import java.util.concurrent.CopyOnWriteArrayList
30
30
import java.util.concurrent.TimeUnit
31
31
import kotlin.coroutines.experimental.CoroutineContext
32
32
33
-
34
33
/* *
35
34
* Dispatches execution onto JavaFx application thread and provides native [delay] support.
36
35
*/
37
36
object JavaFx : CoroutineDispatcher(), Delay {
38
37
init {
39
38
// :kludge: to make sure Toolkit is initialized if we use JavaFx dispatcher outside of JavaFx app
40
- PlatformImpl .startup {}
39
+ initPlatform()
41
40
}
42
41
43
42
private val pulseTimer by lazy {
@@ -93,3 +92,7 @@ object JavaFx : CoroutineDispatcher(), Delay {
93
92
94
93
override fun toString () = " JavaFx"
95
94
}
95
+
96
+ internal fun initPlatform () {
97
+ PlatformImpl .startup {}
98
+ }
Original file line number Diff line number Diff line change @@ -32,16 +32,25 @@ class JavaFxTest : TestBase() {
32
32
}
33
33
34
34
@Test
35
- fun testDelay () = runBlocking {
36
- expect(1 )
37
- val job = launch(JavaFx ) {
38
- check(Platform .isFxApplicationThread())
39
- expect(2 )
40
- delay(100 )
41
- check(Platform .isFxApplicationThread())
42
- expect(3 )
35
+ fun testDelay () {
36
+ try {
37
+ initPlatform()
38
+ } catch (e: UnsupportedOperationException ) {
39
+ println (" Skipping JavaFxTest in headless environment" )
40
+ return // ignore test in headless environments
41
+ }
42
+
43
+ runBlocking {
44
+ expect(1 )
45
+ val job = launch(JavaFx ) {
46
+ check(Platform .isFxApplicationThread())
47
+ expect(2 )
48
+ delay(100 )
49
+ check(Platform .isFxApplicationThread())
50
+ expect(3 )
51
+ }
52
+ job.join()
53
+ finish(4 )
43
54
}
44
- job.join()
45
- finish(4 )
46
55
}
47
56
}
You can’t perform that action at this time.
0 commit comments