Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix bug where customers were sometimes served out of order
  • Loading branch information
bitsai committed Feb 27, 2011
1 parent 19c82f9 commit 94ea08b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sleeping_barber.clj
Expand Up @@ -24,7 +24,7 @@

(def waiting-room
(actor
{:waiting [] :barber-asleep? true}
{:waiting nil :barber-asleep? true}
(fn [{:keys [waiting barber-asleep?] :as state}
[msg-type & args]
sender]
Expand All @@ -39,17 +39,17 @@
(do
(send-msg self :next)
(assoc state
:waiting (conj waiting customer)
:waiting (cons customer waiting)
:barber-asleep? false))
(do
(send-msg sender :wait)
(assoc state
:waiting (conj waiting customer))))))
:waiting (cons customer waiting))))))
:next (if (> (count waiting) 0)
(do
(send-msg barber :enter (first waiting))
(send-msg barber :enter (last waiting))
(assoc state
:waiting (rest waiting)))
:waiting (butlast waiting)))
(do
(send-msg barber :wait)
(assoc state
Expand Down

0 comments on commit 94ea08b

Please sign in to comment.