Akka rules package rules/akka
These rules should apply to code that uses the Akka framework. The provided rules require the libraries
"com.typesafe.akka" %% "akka-actor" % "2.3.3"
"com.typesafe.akka" %% "akka-stream-experimental" % "0.4"
TODO: this requirement should be made more flexible by people who know more about Akka than I do!
name : sender-in-future
source : SenderInFuture
The sender()
method should never be called inside of a code block that won't be executed immediately in the receive
method since the resulting sender might not be the right one anymore when the deferred code is actually executed. For example, the code
class ExampleActor extends Actor {
def receive = {
case "Hi" => future {
sender() ! "Hello"
}
}
}
should be written as
class ExampleActor extends Actor {
def receive = {
case "Hi" =>
val s = sender()
future { s ! "Hello" }
}
}
to make sure the sender we use to reply is indeed the one associated to the received message.