Created
May 30, 2020 15:15
-
-
Save wactbprot/0303a6325c6d22a03d0c04ed0dadc88c to your computer and use it in GitHub Desktop.
start, stop, error, clojure, core.async
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
(ns cmp.system | |
^{:author "wactbprot" | |
:doc "study."} | |
(:require [taoensso.timbre :as timbre] | |
[clojure.core.async :as a])) | |
;;------------------------------ | |
;; kill channel | |
;;------------------------------ | |
(def kill> (a/chan)) | |
;;------------------------------ | |
;; error channel | |
;;------------------------------ | |
(def err< (a/chan)) | |
(defn error-handler | |
[err<] | |
(a/go-loop [] | |
(let [e (a/<! err<)] | |
(if (string? e) | |
(timbre/error e) | |
(timbre/error (.getMessage e)))) | |
(recur))) | |
(defn launch | |
[in> dispatch-fn kill> err<] | |
(a/go-loop [coll (a/alts! [kill> in>] :priority true)] | |
(let [[x ch] coll] | |
(if (= ch kill>) | |
(timbre/warn "receive msg in kill> channel; shutdown") | |
(do | |
(try | |
(dispatch-fn x) | |
(catch Exception e | |
(a/>! err< e))) | |
(recur (a/alts! [kill> in>] :priority true))))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment