/
events.clj
27 lines (25 loc) · 983 Bytes
/
events.clj
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
(ns discljord.events
(:require [clojure.core.async :as a]
[clojure.spec.alpha :as s]
[taoensso.timbre :as log]))
(defn message-pump!
"Starts a process which pulls events off of the channel and calls
handle-event with them, and stops when it sees a :disconnect event.
This takes control of the current thread.
The handle-event function takes the keyword event type, and the event
data."
[event-ch handle-event]
(loop []
(let [[event-type event-data] (a/<!! event-ch)]
(try (handle-event event-type event-data)
(catch Exception e
(log/error e "Exception occurred in event handler.")))
(when-not (= event-type :disconnect)
(recur))))
nil)
(s/fdef message-pump!
:args (s/cat :channel any?
:handle-event (s/fspec :args (s/cat :event-type keyword?
:event-data any?)
:ret any?))
:ret nil?)