Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn perform-request! [url]
- (let [output (chan)]
- (http/get url {} (fn [{:keys [status]}]
- (>! output status)))
- output))
- (defn start-requester! [{:keys [url name]} timeout-value aggr-ch]
- (go
- (alts!
- (timeout timeout-value)
- ([_] (>! aggr-ch {:url url :name name :status 408}))
- (perform-request! url)
- ([status] (>! aggr-ch {:url url :name name :status status})))))
- (defn start-aggregator! [init-count aggr-ch result-ch]
- (go-loop [count init-count
- state []]
- (if (> count 0)
- (recur
- (dec count)
- (conj state (<! aggr-ch)))
- (>! state result-ch))))
- (defn check-availabilities [mappings global-timeout]
- (let [input (map (fn [[k v]] {:name k :url v}) mappings)
- size (count input)
- aggr-ch (chan)
- result-ch (chan)]
- (do-seq [item input] (start-requester! item 250 aggr-ch))
- (start-aggregator! size aggr-ch result-ch)
- (alt!!
- result-ch ([result] result)
- (timeout global-timeout) ([_] {:error :timeout}))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement