Last active
June 27, 2017 14:40
-
-
Save DeTeam/b9dd9d016c7cc474cb7fd36c8532dde0 to your computer and use it in GitHub Desktop.
Example of killing a thread from core async pool. After thread is dead — new one will be created.
This file contains hidden or 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 deteam.core-async-sandbox | |
(:require [clojure.core.async :as async] | |
[clojure.tools.logging :as log])) | |
(def tmp-chan (async/chan 5)) | |
(def waiting-time-ms 500) | |
(defn -main [] | |
(log/info "Started the program") | |
(let | |
[c1 (async/go-loop [] | |
(log/info "Iterating through go-loop") | |
(log/info (format "Got value from the channel: %s" (async/<! tmp-chan))) | |
(recur)) | |
c2 (async/go-loop [a 1] | |
(cond | |
(= a 10) (async/go-loop [] (throw (Exception. "Something bad happened"))) | |
:else (do | |
(log/info "Sending data to the channel") | |
(async/>! tmp-chan a) | |
(async/<! (async/timeout waiting-time-ms)))) | |
(recur (+ a 1)))] | |
(async/<!! (async/merge [c1 c2])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment