I am developing an actor who consumes objects from an endless stream, and he needs a way to control when he starts and stops using messages. Is there a general scheme for implementing discontinuous loops like this with actors? I thought about my actor sending messages to himself. Something like (pseudo Scala):
class Interruptible extends Actor { val stream: Stream val running: boolean def receive = { case "start" => { running = true consumeItem } case "stop" => { running = false } case "consumeNext" => consumeItem } def consumeItem { if (running) { stream.getItem this ! "consumeNext" } } }
Is this the best way to get around things?
Thanks!
source share