1(import [threading [Lock]] [queue [Queue]])
2(require [hy.contrib.walk [let]])
3
4(defclass MSGQueue [object]
5 [QUEUE_SIZE 1]
6
7 (defn --init-- [self]
8 (setv self.map-lock (Lock))
9 (setv self.msgs {}))
10
11 (defn get-queue [self id]
12 (with (self.map-lock)
13 (unless (in id self.msgs)
14 (assoc self.msgs id (Queue self.QUEUE_SIZE))))
15 (get self.msgs id))
16
17 (defn wait [self id]
18 (let [queue (self.get-queue id)
19 msg (queue.get)]
20 (with (self.map-lock)
21 (del queue))
22 msg))
23
24 (defn release [self id msg]
25 (.put-nowait (self.get-queue id) msg)))