Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ciste/feature/manifold
Replace eep with manifold
- Loading branch information
Showing
3 changed files
with
10 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
(ns ciste.event | ||
(:require [clojurewerkz.eep.emitter :as e] | ||
(:require [manifold.bus :as bus] | ||
[slingshot.slingshot :refer [throw+]])) | ||
|
||
(defonce ^:dynamic *keys* (ref {})) | ||
|
||
(defonce emitter | ||
(e/create {:dispatcher-type :ring-buffer})) | ||
(defonce events (bus/event-bus)) | ||
|
||
(defn notify | ||
[channel-key msg] | ||
[topic msg] | ||
;; TODO: make sure that the channel is reqistered | ||
(if-let [d (get @*keys* channel-key)] | ||
(e/notify emitter channel-key (assoc msg :event channel-key)) | ||
(throw+ {:msg (str "No description for key: " channel-key)}))) | ||
(if-let [d (get @*keys* topic)] | ||
(bus/publish! events topic (assoc msg :event topic)) | ||
(throw+ {:msg (str "No description for key: " topic)}))) | ||
|
||
(defn defkey | ||
[channel-key desc & {:as body}] | ||
[topic desc & {:as body}] | ||
(dosync | ||
(alter *keys* assoc channel-key (assoc body :desc desc)))) | ||
(alter *keys* assoc topic (assoc body :desc desc)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters