std.concurrent.bus
bus:all-ids
added in 3.0
(bus:all-ids {:keys [state], :as bus})returns all registered ids
(bus:with-temp bus (bus:all-ids bus)) => (contains #{string?})
bus:all-threads
added in 3.0
(bus:all-threads {:keys [state], :as bus})returns all registered threads
(bus:with-temp bus (= (first (vals (bus:all-threads bus))) (Thread/currentThread))) => true
bus:close
added in 3.0
(bus:close bus id)bus:closes all bus:opened loops
(bus:with-temp bus (let [{:keys stopped id} @(bus:open bus (fn m (update m :value inc)))] (Thread/sleep 10) (bus:close bus id) @stopped (bus:get-count bus))) => (contains-in {:exit :normal, :id string? :unprocessed empty? :start number? :end number?} 1)
bus:deregister
added in 3.0
(bus:deregister bus)(bus:deregister {:keys [state], :as bus} id)deregisters from the bus
bus:get-count
added in 3.0
(bus:get-count {:keys [state], :as bus})returns the number of threads registered
bus:get-id
added in 3.0
(bus:get-id bus)(bus:get-id {:keys [state]} thread)gets registered id given thread
(bus:with-temp bus (bus:get-id bus)) => string?
bus:get-queue
added in 3.0
(bus:get-queue bus)(bus:get-queue {:keys [state], :as bus} obj)gets the message queue associated with the thread
(bus:with-temp bus (vec (bus:get-queue bus))) => []
bus:get-thread
added in 3.0
(bus:get-thread {:keys [state]} id)gets thread given an id
(bus:with-temp bus (->> (bus:get-id bus) (bus:get-thread bus))) => (cc/thread:current)
bus:has-id?
added in 3.0
(bus:has-id? {:keys [state]} id)checks that the bus has a given id
bus:open
added in 3.0
(bus:open bus handler)(bus:open bus handler {:keys [id], :as opts, :or {id (std.lib.foundation/sid)}})bus:register
added in 3.0
(bus:register bus)(bus:register bus id)(bus:register {:keys [state], :as bus} id thread)registers a thread to the bus
bus:send
added in 3.0
(bus:send {:keys [results counters], :as bus} id msg)sends a message to the given thread
bus:wait
added in 3.0
(bus:wait bus)(bus:wait bus {:keys [timeout timeunit], :or {timeunit :ms}})bus:waits on the message queue for message
(bus:with-temp bus (bus:send bus (bus:get-id bus) {:op :hello :message “world”}) (bus:wait bus)) => (contains {:op :hello, :message “world”, :id string?})
(bus:with-temp bus (bus:wait bus {:timeout 100}))
bus:with-temp
macro
added in 3.0
(bus:with-temp var & body)checks if object is instance of Bus
handler-thunk
added in 3.0
(handler-thunk {:keys [output], :as bus} handler {:keys [stopped on-timeout], session-id :id, :as opts})creates a thread loop for given message handler
info-bus
added in 3.0
(info-bus {:keys [state results output counters], :as bus})returns info about the bus
main-loop
added in 3.0
(main-loop {:keys [state], :as bus})creates a new message return loop
main-thunk
added in 3.0
(main-thunk {:keys [results output counters], :as bus})creates main message return handler
run-handler
added in 3.0
(run-handler bus handler)(run-handler bus handler {:keys [id started stopped on-start on-stop], :as opts})runs the handler in a thread loop
started?-bus
added in 3.0
(started?-bus {:keys [state], :as bus})checks if bus is running
(bus:with-temp bus (Thread/sleep 10) (started?-bus bus)) => true