You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.6 KiB

  1. // package org.gerweck.scalafx.akka
  2. // import scala.concurrent._
  3. // import akka.Done
  4. // import akka.stream.OverflowStrategy
  5. // import akka.stream.scaladsl._
  6. // import scalafx.application.Platform.runLater
  7. // import scalafx.beans.property.Property
  8. // import scalafx.beans.value.ObservableValue
  9. // /** A master object that exposes all the Akka-ScalaFX bridges.
  10. // *
  11. // * @author Sarah Gerweck <sarah.a180@gmail.com>
  12. // */
  13. // object AkkaFX extends AkkaStreamFX with AkkaFXCollections
  14. // trait AkkaStreamFX extends Any {
  15. // /** A [[akka.stream.scaladsl.Sink]] that sends all values to a
  16. // * [[scalafx.beans.property.Property]].
  17. // *
  18. // * Each event that's written into the `Sink` will trigger an update of the
  19. // * `Property` with the streamed value.
  20. // */
  21. // def observableSink[A](prop: Property[A, _]): Sink[A, Future[Done]] = {
  22. // Sink.foreach[A] { a =>
  23. // runLater {
  24. // prop.value = a
  25. // }
  26. // }
  27. // }
  28. // /** A [[akka.stream.scaladsl.Source]] that generates an event for each
  29. // * change of an [[scalafx.beans.value.ObservableValue]].
  30. // *
  31. // * This source adds an `onChange` handler to the given `ObservableValue`.
  32. // * Each time it observes a change, the new value is pushed from the
  33. // * `Source`. The change handler is registered as soon as the source is
  34. // * materialized into a graph. It should be safe to use a single source
  35. // * in several graphs, as each will register its own change listener upon
  36. // * materialization.
  37. // *
  38. // * @param prop The value to observe.
  39. // *
  40. // * @param queueSize The maximum number of values to queue while waiting for
  41. // * the downstream flow to consume more data.
  42. // *
  43. // * @param overflow What to do when the queue is full because the downstream
  44. // * flow cannot keep up. The default behavior is to block, slowing the UI's
  45. // * main thread until some events are consumed, freeing space in the queue.
  46. // */
  47. // def observableSource[A](prop: ObservableValue[_, A],
  48. // queueSize: Int = 10,
  49. // overflow: OverflowStrategy = OverflowStrategy.backpressure
  50. // )(implicit ec: ExecutionContext) = {
  51. // val src = Source
  52. // .queue[A](queueSize, overflow)
  53. // .mapMaterializedValue { m =>
  54. // val sub = {
  55. // prop.onChange { (dta, oldV, newV) =>
  56. // m.offer(newV)
  57. // }
  58. // }
  59. // m.watchCompletion() foreach { c =>
  60. // runLater {
  61. // sub.cancel()
  62. // }
  63. // }
  64. // m
  65. // }
  66. // src
  67. // }
  68. // }