Skip to content

Instantly share code, notes, and snippets.

@jastice
Last active December 18, 2015 17:59
Show Gist options
  • Save jastice/5822953 to your computer and use it in GitHub Desktop.
Save jastice/5822953 to your computer and use it in GitHub Desktop.
class IntegrationSuite extends FunSuite with ShouldMatchers {
test("infinit actor") {
val actor= ActorSystem("tail").actorOf(Props[MrActor])
Thread.sleep(10000)
actor ! Interrupt
Thread.sleep(40054)
}
class MrActor extends Actor {
lazy val ps: Stream[Int] = 2 #:: Stream.from(3).filter(i => ps.takeWhile(j => j * j <= i).forall(i % _ > 0))
override def preStart = {
self ! Work(ps)
}
override def receive = working
def working: Receive = {
case Interrupt => become interrupted
case Work(ps) =>
val h = ps.head
// process somehow
self ! Work(ps.tail)
}
def interrupted: Receive = {
case Work(ps) => // ignore?
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment