title: Scala actors as single-threaded queues
body: <p>I'd like to use actors in a program where I'll have some kind of restriction around treating some of the actors as if they were queues. For example, suppose I have some external system to which change events are applied and also some cache of the external system's data. So I have 2 actors:</p>
  
  <ol>
  <li><code>ChangeApplicationActor</code></li>
  <li><code>CacheActor</code></li>
  </ol>
  
  <p>As part of the <code>ChangeApplicationActor</code>, when I apply a change to some entity <code>X</code> in the external system, I want to send some event to tell the <code>CacheActor</code> to sync:</p>
  
  <pre><code>val changeApplicationActor = actor { 
    loop {
      react {
        case ChangeInstruction(x) =&gt; 
          externalSystem.applyChange(x)
          cacheActor ! Sync(x)
      }
    }
  }
  </code></pre>
  
  <p>But I Now have two requirements:</p>
  
  <ol>
  <li>The <code>CacheActor</code> has internal state and ideally I'd like it to process its <code>Sync</code> instructions sequentially</li>
  <li>If I end up with the <code>CacheActor</code>'s inbox containing two <code>Sync(x)</code> instructions for the same value of <code>x</code>, then I'd like to ignore the second one (i.e. I should only have one pending <code>Sync</code> instruction for any given value of <code>x</code>)</li>
  </ol>
  
  <p>Is there any way of forcing an actor to be single-threaded? Is there any way I can access the actor's mailbox and remove any duplicate events? Can I not avoid implementing the <code>CacheActor</code> as, um, <em>not an Actor</em>?</p>