Advertisement
Guest User

Untitled

a guest
Nov 30th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.15 KB | None | 0 0
  1.   def live = {
  2.     import scala.concurrent.{Future, Promise, ExecutionContext}
  3.     import scala.swing.event._
  4.  
  5.     implicit val executionContext = ExecutionContext fromExecutorService Executors.newCachedThreadPool()
  6.  
  7.     def stepCommand: Future[Unit] = {
  8.       val promise = Promise[Unit]()
  9.       new Reactor {
  10.         stepButton.enabled = true
  11.         listenTo(stepButton)
  12.         reactions += {case _: ButtonClicked => promise.success(()); deafTo(stepButton)}
  13.       }
  14.       promise.future
  15.     }
  16.  
  17.     def autoStepCommand: Future[Unit] = {
  18.       lazy val never = Promise[Unit]().future
  19.       if (autoCheckBox.selected) Future {waitForStepTimeout} else never
  20.     }
  21.  
  22.     def again: Unit = Future {awaitMessageBeingHandled(true)}.flatMap {_ =>
  23.       if (shouldStep) {
  24.         Swing.onEDTWait(updateDisplay)
  25.         Future firstCompletedOf Seq(stepCommand, autoStepCommand)
  26.       } else Future.successful(())
  27.     }.onSuccess {case _ =>
  28.       messageBeingHandled(false)
  29.       again
  30.     }
  31.  
  32.     new Reactor {
  33.       exitButton.enabled = true
  34.       listenTo(exitButton)
  35.       reactions += {case _: ButtonClicked => System.exit(1)}
  36.     }
  37.  
  38.     again
  39.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement