Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

FSM.once doesn't work #89

Open
vsuharnikov opened this issue Jun 22, 2016 · 0 comments
Open

FSM.once doesn't work #89

vsuharnikov opened this issue Jun 22, 2016 · 0 comments

Comments

@vsuharnikov
Copy link
Contributor

Example:

import moorka._

import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import java.util.{Timer, TimerTask}

import scala.concurrent.Promise

val timer = new Timer(true)

// === Essence
def fsm = FSM(0) {
  case 5  Dummy
  case x  after(1 second).toRx.map { _ 
    println(s"x: $x")
    x + 1
  }
}

// Will not print anything
fsm once println

// Will print "0"
fsm flatMap { x 
  println(x)
  Killer
}

// === /Essence

def after(timeout: FiniteDuration): Future[Unit] = {
  val p = Promise[Unit]()
  val task = new TimerTask {
    override def run(): Unit = {
      p.success(())
    }
  }

  timer.schedule(task, timeout.toMillis)

  p.future
}
  • Moorka 0.7.1
  • Scala.JS 0.6.10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant