parent
63ccdeec16
commit
b1df13d4d4
221 changed files with 1528 additions and 1580 deletions
|
|
@ -11,7 +11,7 @@ import scala.concurrent.{ ExecutionContext, Future }
|
|||
// #blocking-in-actor
|
||||
class BlockingActor extends Actor {
|
||||
def receive = {
|
||||
case i: Int =>
|
||||
case i: Int ⇒
|
||||
Thread.sleep(5000) //block for 5 seconds, representing blocking I/O, etc
|
||||
println(s"Blocking operation finished: ${i}")
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ class BlockingFutureActor extends Actor {
|
|||
implicit val executionContext: ExecutionContext = context.dispatcher
|
||||
|
||||
def receive = {
|
||||
case i: Int =>
|
||||
case i: Int ⇒
|
||||
println(s"Calling blocking Future: ${i}")
|
||||
Future {
|
||||
Thread.sleep(5000) //block for 5 seconds
|
||||
|
|
@ -38,7 +38,7 @@ class SeparateDispatcherFutureActor extends Actor {
|
|||
implicit val executionContext: ExecutionContext = context.system.dispatchers.lookup("my-blocking-dispatcher")
|
||||
|
||||
def receive = {
|
||||
case i: Int =>
|
||||
case i: Int ⇒
|
||||
println(s"Calling blocking Future: ${i}")
|
||||
Future {
|
||||
Thread.sleep(5000) //block for 5 seconds
|
||||
|
|
@ -51,7 +51,7 @@ class SeparateDispatcherFutureActor extends Actor {
|
|||
// #print-actor
|
||||
class PrintActor extends Actor {
|
||||
def receive = {
|
||||
case i: Int =>
|
||||
case i: Int ⇒
|
||||
println(s"PrintActor: ${i}")
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ object BlockingDispatcherSample {
|
|||
val actor1 = system.actorOf(Props(new BlockingFutureActor))
|
||||
val actor2 = system.actorOf(Props(new PrintActor))
|
||||
|
||||
for (i <- 1 to 100) {
|
||||
for (i ← 1 to 100) {
|
||||
actor1 ! i
|
||||
actor2 ! i
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ object SeparateDispatcherSample {
|
|||
val actor1 = system.actorOf(Props(new SeparateDispatcherFutureActor))
|
||||
val actor2 = system.actorOf(Props(new PrintActor))
|
||||
|
||||
for (i <- 1 to 100) {
|
||||
for (i ← 1 to 100) {
|
||||
actor1 ! i
|
||||
actor2 ! i
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue