Skip to content

Commit 0673361

Browse files
committed
Fixes
1 parent 6e5c79d commit 0673361

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

ui/kotlinx-coroutines-javafx/src/JavaFxConvert.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
15
package kotlinx.coroutines.javafx
26

37
import javafx.beans.value.ChangeListener
@@ -20,9 +24,16 @@ import kotlinx.coroutines.flow.flowOn
2024
*
2125
* Since this implementation uses [ObservableValue.addListener], even if this [ObservableValue]
2226
* supports lazy evaluation, eager computation will be enforced while the flow is being collected.
27+
*
28+
* All the calls to JavaFX API are performed in the JavaFX application thread.
29+
*
30+
* ### Operator fusion
31+
*
32+
* Adjacent applications of [flowOn], [buffer], [conflate], and [produceIn] to the result of `asFlow` are fused.
33+
* [conflate] has no effect, as this flow is already conflated; one can use [buffer] to change that instead.
2334
*/
2435
@ExperimentalCoroutinesApi
25-
public fun <T: Any> ObservableValue<T>.asFlow(): Flow<T> = callbackFlow<T> {
36+
public fun <T> ObservableValue<T>.asFlow(): Flow<T> = callbackFlow<T> {
2637
val listener = ChangeListener<T> { _, _, newValue ->
2738
try {
2839
offer(newValue)

ui/kotlinx-coroutines-javafx/test/JavaFxObservableAsFlowTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class JavaFxObservableAsFlowTest : TestBase() {
2424
}
2525

2626
val integerProperty = SimpleIntegerProperty(0)
27-
val n = 10000 * stressTestMultiplier
27+
val n = 1000
2828
val flow = integerProperty.asFlow().takeWhile { j -> j != n }
2929
newSingleThreadContext("setter").use { pool ->
3030
launch(pool) {

ui/kotlinx-coroutines-javafx/test/JavaFxStressTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class JavaFxStressTest : TestBase() {
1414
}
1515

1616
@Test
17-
fun cancellationRaceStressTest() = runTest {
17+
fun testCancellationRace() = runTest {
1818
if (!initPlatform()) {
1919
println("Skipping JavaFxTest in headless environment")
2020
return@runTest // ignore test in headless environments

ui/kotlinx-coroutines-javafx/test/examples/FxAsFlow.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class FxAsFlowApp: Application(), CoroutineScope {
2626
override val coroutineContext: CoroutineContext
2727
get() = JavaFx + job
2828

29-
private val incrementBttn = Button("Increment")
30-
private val incrementLabel = Label("")
31-
private val textInput = TextField()
32-
private val flippedTextLabel = Label()
33-
private val spinner = Spinner<Int>()
34-
private val spinnerChangesLabel = Label()
29+
private val incrementBttn = Button("Increment")
30+
private val incrementLabel = Label("")
31+
private val textInput = TextField()
32+
private val flippedTextLabel = Label()
33+
private val spinner = Spinner<Int>()
34+
private val spinnerChangesLabel = Label()
3535

3636
public override fun start( primaryStage: Stage) {
3737
val gridPane = GridPane()
@@ -61,7 +61,7 @@ class FxAsFlowApp: Application(), CoroutineScope {
6161

6262
init {
6363
// Initializing the "Increment" button
64-
val stringProperty = SimpleStringProperty("")
64+
val stringProperty = SimpleStringProperty()
6565
var i = 0
6666
incrementBttn.onAction = EventHandler {
6767
i += 1
@@ -76,7 +76,7 @@ class FxAsFlowApp: Application(), CoroutineScope {
7676
}
7777
incrementLabel.textProperty().bind(stringProperty)
7878
// Initializing the reversed text field
79-
val stringProperty2 = SimpleStringProperty("")
79+
val stringProperty2 = SimpleStringProperty()
8080
launch {
8181
textInput.textProperty().asFlow().collect {
8282
if (it != null) {
@@ -88,7 +88,7 @@ class FxAsFlowApp: Application(), CoroutineScope {
8888
// Initializing the spinner
8989
spinner.valueFactory = SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100)
9090
spinner.isEditable = true
91-
val stringProperty3 = SimpleStringProperty("")
91+
val stringProperty3 = SimpleStringProperty()
9292
launch {
9393
spinner.valueProperty().asFlow().collect {
9494
if (it != null) {

0 commit comments

Comments
 (0)