Skip to content

Instantly share code, notes, and snippets.

@kungfoo
Created July 10, 2019 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kungfoo/95e8b034bcd2297b5341711223e63460 to your computer and use it in GitHub Desktop.
Save kungfoo/95e8b034bcd2297b5341711223e63460 to your computer and use it in GitHub Desktop.
Really cool sala actor sample
class SecurityPricingActor(exchange: Exchange, backOffice: BackOffice) extends Actor {
def receive = {
case GetPricingInfo(security: Security) =>
val originalSender = sender
val bidAndAskFuture = Future { exchange.getBidAndAsk(security.id) }
val lastPriceFuture = Future { backOffice.getLastPrice(security.id) }
val response = for {
(bid, ask) = bidAndAskFuture
lastPrice = lastPriceFuture
} yield SecurityPricing(bid, ask, lastPrice)
response map (originalSender ! _)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment