Skip to content

Commit

Permalink
Document pop-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
joodie committed Jan 28, 2025
1 parent c7b54f6 commit c7cea4d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/nl/surf/eduhub/validator/service/jobs/client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
(is (= http-status/ok status))
body))

;; TODO: Explain what this does and why
(defn- pop-queue! [atm]
(let [old-val @atm]
(defn- pop-queue!
"Remove and return first item from `queue-atom`.
Returns `nil` if queue-atom is empty."
[queue-atom]
(let [old-val @queue-atom]
(when-not (empty? old-val)
(let [item (peek old-val)
new-val (pop old-val)]
(if (compare-and-set! atm old-val new-val)
(if (compare-and-set! queue-atom old-val new-val)
item
(pop-queue! atm))))))
(pop-queue! queue-atom))))))

(deftest test-queue
(testing "initial call to api"
Expand Down

0 comments on commit c7cea4d

Please sign in to comment.