org.marid.fx.extensions.ConcurrentPropertiesExtensions.kt Maven / Gradle / Ivy
package org.marid.fx.extensions
import javafx.application.Platform
import javafx.beans.binding.IntegerBinding
import javafx.beans.value.*
import java.util.concurrent.CompletableFuture
typealias ObservableIntValue = ObservableIntegerValue
typealias IntBinding = IntegerBinding
val ObservableIntegerValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(get())
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(get()) }
future
}
val ObservableLongValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(get())
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(get()) }
future
}
val ObservableFloatValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(get())
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(get()) }
future
}
val ObservableDoubleValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(get())
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(get()) }
future
}
val ObservableStringValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(get())
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(get()) }
future
}
val ObservableBooleanValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(get())
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(get()) }
future
}
val ObservableValue.safe: CompletableFuture
get() = if (Platform.isFxApplicationThread()) {
CompletableFuture.completedFuture(value)
} else {
val future = CompletableFuture()
Platform.runLater { future.complete(value) }
future
}