Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
master: Moved future from directly in core to a function to prevent c…
Browse files Browse the repository at this point in the history
…ompliation errors.
  • Loading branch information
mikeflynn committed Jun 14, 2015
1 parent d96814d commit 2e15b4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject beats-clj "0.9.4"
(defproject beats-clj "0.9.5"
:description "A Clojure library to interact with the Beats Music API."
:url "https://mikeflynn.github.io/beats-clj"
:license {:name "Eclipse Public License"
Expand Down
9 changes: 8 additions & 1 deletion src/beats_clj/core.clj
Expand Up @@ -10,9 +10,15 @@
(def #^{:dynamic true :no-doc true} *app-secret* false)

; Rate Limiting
(def #^{:dynamic true} *rate-counter-on* false)
(def #^{:no-doc true} rate-counter-on false)
(def #^{:no-doc true} rate-counter (atom 0))
(def #^{:no-doc true} max-per-second 15)
(future (while true (do (Thread/sleep 1000) (reset! rate-counter 0))))

(defn start-rate-counter []
(when (not *rate-counter-on*)
(do (future (while true (do (Thread/sleep 1000) (reset! rate-counter 0))))
(alter-var-root (var *rate-counter-on*) (fn [_] true)))))

; Main
(defn set-app-key!
Expand Down Expand Up @@ -67,6 +73,7 @@
:or {resp :json}}]
(when (not *app-secret*) (throw (Exception. "Missing Beats app secret!")))
(when (not *app-key*) (throw (Exception. "Missing Beats app key!")))
(start-rate-counter)
(when (> (swap! rate-counter inc) max-per-second)
(Thread/sleep 1000))
(let [params (if (not (contains? params "client_id")) (assoc params :client_id *app-key*) params)
Expand Down

0 comments on commit 2e15b4d

Please sign in to comment.