Making it possible/mandatory to signal which ExecutionContext will actually execute something scheduled
This commit is contained in:
parent
a8f648ef1c
commit
9d097bcf50
22 changed files with 135 additions and 120 deletions
|
|
@ -91,6 +91,7 @@ class Worker extends Actor with ActorLogging {
|
|||
var progressListener: Option[ActorRef] = None
|
||||
val counterService = context.actorOf(Props[CounterService], name = "counter")
|
||||
val totalCount = 51
|
||||
import context.dispatcher // Use this Actors' Dispatcher as ExecutionContext
|
||||
|
||||
def receive = LoggingReceive {
|
||||
case Start if progressListener.isEmpty ⇒
|
||||
|
|
@ -103,7 +104,6 @@ class Worker extends Actor with ActorLogging {
|
|||
counterService ! Increment(1)
|
||||
|
||||
// Send current progress to the initial sender
|
||||
import context.dispatcher // Use this Actors' Dispatcher as ExecutionContext
|
||||
counterService ? GetCurrentCount map {
|
||||
case CurrentCount(_, count) ⇒ Progress(100.0 * count / totalCount)
|
||||
} pipeTo progressListener.get
|
||||
|
|
@ -143,6 +143,8 @@ class CounterService extends Actor {
|
|||
var backlog = IndexedSeq.empty[(ActorRef, Any)]
|
||||
val MaxBacklog = 10000
|
||||
|
||||
import context.dispatcher // Use this Actors' Dispatcher as ExecutionContext
|
||||
|
||||
override def preStart() {
|
||||
initStorage()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ import akka.testkit._
|
|||
class SchedulerDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
||||
"schedule a one-off task" in {
|
||||
//#schedule-one-off-message
|
||||
//Use the system's dispatcher as ExecutionContext
|
||||
import system.dispatcher
|
||||
|
||||
//Schedules to send the "foo"-message to the testActor after 50ms
|
||||
system.scheduler.scheduleOnce(50 milliseconds, testActor, "foo")
|
||||
//#schedule-one-off-message
|
||||
|
|
@ -42,6 +45,9 @@ class SchedulerDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
|||
case Tick ⇒ //Do something
|
||||
}
|
||||
}))
|
||||
//Use system's dispatcher as ExecutionContext
|
||||
import system.dispatcher
|
||||
|
||||
//This will schedule to send the Tick-message
|
||||
//to the tickActor after 0ms repeating every 50ms
|
||||
val cancellable =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue