Skip to content

Instantly share code, notes, and snippets.

@marcoy
Last active November 12, 2020 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoy/983b8b346ed9ecc4a55a to your computer and use it in GitHub Desktop.
Save marcoy/983b8b346ed9ecc4a55a to your computer and use it in GitHub Desktop.
Change core.async threadpool
;; http://stackoverflow.com/questions/18779296/clojure-core-async-any-way-to-control-number-of-threads-in-that-go-thread
(ns sandbox
(:require [clojure.core.async.impl.concurrent :as conc]
[clojure.core.async.impl.exec.threadpool :as tp]
[clojure.core.async :as async]))
(defonce my-executor
(java.util.concurrent.Executors/newFixedThreadPool
1
(conc/counted-thread-factory "my-async-dispatch-%d" true)))
(alter-var-root #'clojure.core.async.impl.dispatch/executor
(constantly (delay (tp/thread-pool-executor my-executor))))
(async/go
(println
(Thread/currentThread))) ;=> #<Thread Thread[my-async-dispatch-1,5,main]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment