summaryrefslogtreecommitdiff
path: root/vim/bundle/slimv/swank-clojure/swank/util/concurrent/mbox.clj
blob: 8c30d74c923e7495953aefcf0c7de7b2d7bd206f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns swank.util.concurrent.mbox
  (:refer-clojure :exclude [send get]))

;; Holds references to the mailboxes (message queues)
(defonce mailboxes (ref {}))

(defn get
  "Returns the mailbox for a given id. Creates one if one does not
   already exist."
  ([id]
     (dosync
      (when-not (@mailboxes id)
        (alter mailboxes assoc
               id (java.util.concurrent.LinkedBlockingQueue.))))
     (@mailboxes id))
  {:tag java.util.concurrent.LinkedBlockingQueue})

(defn send
  "Sends a message to a given id."
  ([id message]
     (let [mbox (get id)]
       (.put mbox message))))

(defn receive
  "Blocking recieve for messages for the given id."
  ([id]
     (let [mb (get id)]
       (.take mb))))

(defn clean []
  )