Skip to content

Instantly share code, notes, and snippets.

@raspasov
Last active January 7, 2021 09:50
Show Gist options
  • Save raspasov/e0081d6de5f61648311c3a598e1f8941 to your computer and use it in GitHub Desktop.
Save raspasov/e0081d6de5f61648311c3a598e1f8941 to your computer and use it in GitHub Desktop.
core.async agents experiment
(ns scratch
(:require [clojure.core.async :as a]
[taoensso.timbre :as timbre]))
(def core-async-agent-state (atom 0))
(def core-async-agent-ch (a/chan 1))
(def p2
(a/pipeline-blocking
1
;To (black hole)
(a/chan (a/sliding-buffer 1) (map (fn [task-finished]
(timbre/spy task-finished))))
;Xf
(map (fn [task]
(timbre/spy task)
;TODO do something...
(swap! core-async-agent-state (fn [x] (inc x)))
task))
;from
core-async-agent-ch))
(defn run-go [wait-ms]
(a/go
(let [task-status (a/alts! [[core-async-agent-ch :a-task] (a/timeout wait-ms)])
submit-ok? (first task-status)]
(timbre/spy submit-ok?)
#_(timbre/spy task-status))))
(comment
(let [wait-ms 20]
(repeatedly
500
#(run-go wait-ms))))
(comment
;check state
(do
@core-async-agent-state))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment