-
-
Save conikeec/1861662 to your computer and use it in GitHub Desktop.
Futures and Resizers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.dispatch.Future | |
import akka.pattern.pipe | |
import akka.actor.Actor | |
case class Work(s: String) | |
case class Result(s: String) | |
object MyActor { | |
// put here to avoid closing over actor’s state | |
def doWork(work: String): String = { | |
// this takes very long | |
"hello " + work | |
} | |
} | |
class MyActor extends Actor { | |
import context.dispatcher | |
def receive = { | |
case Work(w) => | |
Future { Result(MyActor.doWork(w)) } pipeTo sender | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{ Props, ActorSystem } | |
import akka.routing.{ RoundRobinRouter, DefaultResizer } | |
object Demo { | |
val system = ActorSystem() | |
val flexibleRouter = system.actorOf(Props.empty.withRouter( | |
RoundRobinRouter(resizer = Some(DefaultResizer( | |
lowerBound = 1, upperBound = 10))))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment