Skip to content

Instantly share code, notes, and snippets.

@rbnpercy
Created July 10, 2020 15:20
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 rbnpercy/3074a390b40f70181cfb567447c93101 to your computer and use it in GitHub Desktop.
Save rbnpercy/3074a390b40f70181cfb567447c93101 to your computer and use it in GitHub Desktop.
(defn task-queue
"Creates `core.async` channel which will process 0 arg functions put there in serial fashon.
Takes the same argument/s as `core.async/chan`, those arguments will be delegated to the
channel constructor.
Returns task-queue where tasks represented by 0 arg task functions can be put for processing."
[& args]
(let [task-queue (apply async/chan args)]
(async/go-loop [task-fn (async/<! task-queue)]
(run-task task-fn)
(recur (async/<! task-queue)))
task-queue))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment