bilal-fazlani / akka-scala-blog Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
https://medium.com/swlh/actors-using-scala-akka-part-2-askpattern-and-spawnprotocol-3942e45a5fcc
for {
bankAccount <- bankAccountFuture
balance1 <- bankAccount ? GetBalance
_ = println(balance1)
_ = bankAccount ! Deposit(200)
_ = bankAccount ! Withdraw(50)
balance2 <- bankAccount ? GetBalance
_ = println(balance2)
} yield ()
If this is intended to model transactions in a sequential stepwise fashion (e.g., deposit 200 then withdraw 50), this example is perhaps misleading.
I believe the order of sending (fire-and-forget/tell) messages in that map
call are not necessarily the order that the recieving Actor
would be processing the messages.
https://doc.akka.io/docs/akka/current/typed/interaction-patterns.html#fire-and-forget
To make the processing ordered, it would be necessary to use an ask
and modify the message protocol to have return "response" message or status.
Something along the lines of this:
val myFut = for {
bankAccount <- bankAccountFuture
balance1 <- bankAccount ? GetBalance
msg1 <- bankAccount ? Deposit(200)
msg2 <- bankAccount ? Withdraw(50)
finalBalance <- bankAccount ? GetBalance
} yield finalBalance
Also, the actorSystem.terminate()
call in your example can exit before all the futures have been processed. I suspect this needs an Await.result(myFut, Duration.Inf)
call before the terminate()
call of the actor system.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.