Code Monkey home page Code Monkey logo

akka-scala-blog's Introduction

Bilal Fazlani

akka-scala-blog's People

Contributors

bilal-fazlani avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

akka-scala-blog's Issues

Clarify intended usage of Tell

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.