Skip to content

Instantly share code, notes, and snippets.

@monadplus
Created April 1, 2019 07:00
Show Gist options
  • Save monadplus/c460e75ab3b889a31bf3a8c1f35f29a4 to your computer and use it in GitHub Desktop.
Save monadplus/c460e75ab3b889a31bf3a8c1f35f29a4 to your computer and use it in GitHub Desktop.
Killing an actor is a cooperative task
// Stopping the loop actor:
// - Raw PoisonPill didn't work.
// - context.stop(loopActor) didn't work.
// - Thread.interrupted() is never triggered by PoisonPill, Kill nor stop.
class LoopActor extends Actor {
var isInterrupted = false
override def postStop(): Unit = println("Stopping...")
override def receive: Receive = {
case "loop" =>
while(!isInterrupted) {
println("Inside the while loop")
if (Thread.interrupted()) {
isInterrupted = true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment