Created
April 1, 2019 07:00
-
-
Save monadplus/c460e75ab3b889a31bf3a8c1f35f29a4 to your computer and use it in GitHub Desktop.
Killing an actor is a cooperative task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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