Update FutureObservable
to perform much better
This commit is contained in:
parent
83d7f5f009
commit
941d0c7cb7
@ -1,6 +1,7 @@
|
|||||||
package org.gerweck.scalafx.util
|
package org.gerweck.scalafx.util
|
||||||
|
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
|
import scala.util._
|
||||||
|
|
||||||
import org.log4s._
|
import org.log4s._
|
||||||
|
|
||||||
@ -27,13 +28,23 @@ object FutureObservable {
|
|||||||
* is already a built-in feature.
|
* is already a built-in feature.
|
||||||
*/
|
*/
|
||||||
def apply[A](defaultValue: A)(future: Future[A])(implicit ec: ExecutionContext): ReadOnlyObjectProperty[A] = {
|
def apply[A](defaultValue: A)(future: Future[A])(implicit ec: ExecutionContext): ReadOnlyObjectProperty[A] = {
|
||||||
val prop = ObjectProperty[A](defaultValue)
|
logger.debug(s"Got request to create new FutureObservable")
|
||||||
future onSuccess { case a =>
|
future.value match {
|
||||||
runLater {
|
case Some(Success(a)) =>
|
||||||
logger.trace("Updating property value after Future's success")
|
ObjectProperty(a)
|
||||||
prop.value = a
|
|
||||||
}
|
case Some(Failure(f)) =>
|
||||||
|
logger.info(s"Got failure from FutureObservable's result: $f")
|
||||||
|
ObjectProperty(defaultValue)
|
||||||
|
|
||||||
|
case None =>
|
||||||
|
val prop = ObjectProperty[A](defaultValue)
|
||||||
|
future onSuccess { case a =>
|
||||||
|
runLater {
|
||||||
|
prop.value = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prop
|
||||||
}
|
}
|
||||||
prop
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user