Skip to content

Instantly share code, notes, and snippets.

@DeTeam
Last active June 27, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeTeam/b9dd9d016c7cc474cb7fd36c8532dde0 to your computer and use it in GitHub Desktop.
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.
(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