std.concurrent
->timeunit
added in 3.0
(->timeunit obj)returns the timeunit
(q/->timeunit :ms) => java.util.concurrent.TimeUnit/MILLISECONDS
aq:executor
added in 3.0
(aq:executor {:keys [target], :as opts})creates a executor that takes in an atom queue
aq:process
added in 3.0
(aq:process f aq max-batch)aq:submit
added in 3.0
(aq:submit executor queue {:keys [target handler max-batch interval], :as opts})submission function for one or multiple entries to aq
bulk
added in 3.0
(bulk client thunk)(bulk client thunk opts)allows query inputs to be combined
bulk:map
added in 3.0
(bulk:map client f inputs)(bulk:map client f inputs opts)map function across a client
bulk:transact
added in 3.0
(bulk:transact client thunk)(bulk:transact client thunk opts)creates a transaction within a bulk context
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
deque
added in 3.0
(deque)(deque & elements)constructs a blocking deque
(q/deque 1 2 3) => java.util.concurrent.LinkedBlockingDeque
drain
added in 3.0
(drain queue)(drain queue max)(drain queue max target)exec:at-capacity?
added in 3.0
(exec:at-capacity? executor)checks if executor is at capacity
exec:await-termination
added in 3.0
(exec:await-termination service)(exec:await-termination service ms)await termination for executor service
exec:current-active
added in 3.0
(exec:current-active service)returns number of active threads in pool
exec:current-completed
added in 3.0
(exec:current-completed service)returns number of completed tasks
exec:current-size
added in 3.0
(exec:current-size service)returns number of threads in pool
exec:current-submitted
added in 3.0
(exec:current-submitted service)returns number of submitted tasks
exec:get-queue
added in 3.0
(exec:get-queue service)gets the queue from the executor
(-> (executor:pool 10 10 1000 (q/queue)) (exec:get-queue))
exec:increase-capacity
added in 3.0
(exec:increase-capacity executor)(exec:increase-capacity executor n)increases the capacity of the executor
exec:keep-alive
added in 3.0
(exec:keep-alive service)(exec:keep-alive service length)gets and sets the keep alive time
exec:pool-max
added in 3.0
(exec:pool-max service)(exec:pool-max service size)gets and sets the core pool max
exec:pool-size
added in 3.0
(exec:pool-size service)(exec:pool-size service size)gets and sets the core pool size
exec:queue
added in 3.0
(exec:queue)(exec:queue arg)contructs a raw queue in different ways
(exec:queue)
(exec:queue 1)
(exec:queue {:size 1})
(exec:queue {})
(exec:queue (q/queue))
exec:rejected-handler
added in 3.0
(exec:rejected-handler service)(exec:rejected-handler service f)sets the rejected task handler
exec:terminated?
added in 3.0
(exec:terminated? service)checks if executor is shutdown and all threads have finished
exec:terminating?
added in 3.0
(exec:terminating? service)check that executor is terminating
executor
multimethod
added in 3.0
creates an executor
(executor {:type :pool :size 3 :max 3 :keep-alive 1000})
executor:info
added in 3.0
(executor:info executor)(executor:info executor k)returns executor service info
executor:pool
added in 3.0
(executor:pool size max keep-alive)(executor:pool size max keep-alive size-or-queue)constructs a pool executor
(executor:pool 10 10 1000 {:size 10})
executor:props
added in 3.0
(executor:props executor)returns props for getters and setters
executor:scheduled
added in 3.0
(executor:scheduled size)constructs a scheduled executor
(executor:scheduled 10)
executor:single
added in 3.0
(executor:single)(executor:single size-or-queue)constructs a single executor
;; any sized pool (executor:single)
;; fixed pool (executor:single {:size 10})
hub:add-entries
added in 3.0
(hub:add-entries hub entries)adds entries to the hub
(hub:add-entries (hub:new) 1 2 3 4 5) => (contains f/future? 0 5)
hub:executor
added in 3.0
(hub:executor object {:keys [handler max-batch interval], :as opts})creates a hub based executor
(def -exe- (hub:executor nil {:handler (fn & args args) :interval 50 :max-batch 1000}))
(do (def -res- ((:submit -exe-) 1 2 3 4 5 6)) @(first -res-)) => ’(nil (1 2 3 4 5 6))
(hub:wait (:queue -exe-)) => nil
hub:process
added in 3.0
(hub:process f hub max-batch)hub:submit
added in 3.0
(hub:submit object executor hub {:keys [handler max-batch interval]})submission function for the hub
pool
added in 3.0
(pool {:keys [size max keep-alive poll resource], :as m})pool:acquire
added in 3.0
(pool:acquire {:keys [state resource], :as pool})acquires a resource from the pool
(pool:acquire |pool|) => (contains string? ’
pool:cleanup
added in 3.0
(pool:cleanup {:keys [state], :as pool})runs cleanup on the pool
pool:create
added in 3.0
(pool:create m)creates an initial pool
(pool:create {:size 5 :max 8 :keep-alive 10000 :poll 20000 :resource {:create (fn [] ’
pool:dispose
added in 3.0
(pool:dispose {:keys [state resource], :as pool} id)disposes an idle object
(pool:dispose |pool| (first (keys (pool:resources:idle |pool|))))
pool:dispose-over
added in 3.0
(pool:dispose-over {:keys [state resource], :as pool} id)disposes if idle and busy are over size limit
pool:dispose:unmark
added in 3.0
(pool:dispose:unmark)unmarks the current resource for dispose
pool:release
added in 3.0
(pool:release pool id)(pool:release {:keys [state], :as pool} id dispose?)releases a resource back to the pool
(let [id _(pool:acquire |pool|)] (pool:release |pool| id)) => string?
pool:resources:busy
added in 3.0
(pool:resources:busy {:keys [state], :as pool})returns all the busy resources
pool:resources:idle
added in 3.0
(pool:resources:idle {:keys [state], :as pool})returns all the idle resources
pool:resources:thread
added in 3.0
(pool:resources:thread pool)(pool:resources:thread {:keys [state], :as pool} thread)returns acquired resources for a given thread
pool:with-resource
macro
added in 3.0
(pool:with-resource [obj pool] & body)takes an object from the pool, performs operation then returns it
process-bulk
(process-bulk client inputs outputs)(process-bulk client inputs outputs opts)process-bulk
added in 3.0
(process-bulk f queue maximum)put
added in 3.0
(put queue element)(put queue element timeout)(put queue element timeout timeunit)puts an element at the back
(->> (doto (q/queue) (q/put 1)) (into [])) => 1
put-first
added in 3.0
(put-first queue element)(put-first queue element timeout)(put-first queue element timeout timeunit)puts at the front of the queue
put-last
added in 3.0
(put-last queue element)(put-last queue element timeout)(put-last queue element timeout timeunit)puts at the back of the queue
queue
added in 3.0
(queue)(queue & elements)constructs a blocking queue
(q/queue 1 2 3) => java.util.concurrent.LinkedBlockingQueue
queue:fixed
added in 3.0
(queue:fixed size)constructs a fixed size blocking queue
(type (q/queue:fixed 10)) => java.util.concurrent.ArrayBlockingQueue
queue:limited
added in 3.0
(queue:limited size)constructs a limited queue
(q/queue:limited 10)
remaining-capacity
added in 3.0
(remaining-capacity queue)returns the remaining capacity
(q/remaining-capacity (q/queue)) => 2147483647
(q/remaining-capacity (doto (q/queue:fixed 2) (q/put 1))) => 1
req
macro
added in 3.0
(req client command)(req client command opts)execute command on single, bulk and transact calls
(req |client| {:type :eval :form 1})
req:opts
added in 3.0
(req:opts opts)(req:opts opts {:keys [pre post chain], :as m})clean opts for processing inputs
req:run
added in 3.0
(req:run command client args)(req:run {:keys [options process], :as command} client args opts)runs a command
req:transact
macro
added in 3.0
(req:transact [client opts] & body)creates a bulk transaction request
schedule
added in 3.0
(schedule service f interval)(schedule service f interval {:keys [min]})schedules task for execution
schedule:fixed-delay
added in 3.0
(schedule:fixed-delay service f delay)(schedule:fixed-delay service f delay {:keys [initial min]})schedules task at fixed delay
schedule:fixed-rate
added in 3.0
(schedule:fixed-rate service f interval)(schedule:fixed-rate service f interval {:keys [initial min]})schedules task at a fixed rate
stacktrace
added in 3.0
(stacktrace)(stacktrace thread)returns thread stacktrace
(stacktrace)
submit
added in 3.0
(submit service f)(submit service f {:keys [min max delay default], :as m})submits a task to an executor
@(submit (executor:single) (fn []) {:min 100}) ^hidden
@(submit (executor:single) (fn [] (Thread/sleep 1000)) {:max 100}) => (throws)
submit-notify
added in 3.0
(submit-notify service f)(submit-notify service f {:keys [min max delay default], :as m})submits a task (generally to a fixed size queue)
(doto (executor:single 1) (submit-notify (fn []) 1000) (submit-notify (fn []) 1000) (submit-notify (fn []) 1000))
take
added in 3.0
(take queue)(take queue timeout)(take queue timeout timeunit)takes an element from the queue
((juxt q/take #(into [] %)) (q/queue 1 2 3)) => [1 2 3]
take-first
added in 3.0
(take-first queue)(take-first queue timeout)(take-first queue timeout timeunit)takes from the front of the queue
take-last
added in 3.0
(take-last queue)(take-last queue timeout)(take-last queue timeout timeunit)takes from the back of the queue
thread
added in 3.0
(thread {:keys [handler daemon priority classloader uncaught name start]})creates a new thread
thread:classloader
added in 3.0
(thread:classloader)(thread:classloader thread)(thread:classloader thread loader)gets and sets the context classloader
thread:daemon?
added in 3.0
(thread:daemon?)(thread:daemon? thread)checks if thread is a daemon
thread:global-uncaught
added in 3.0
(thread:global-uncaught)(thread:global-uncaught f)gets and sets the global uncaught exception handler
thread:has-access?
added in 3.0
(thread:has-access? thread)checks if thread allows access to current
thread:interrupted?
added in 3.0
(thread:interrupted? thread)checks if thread has been interrupted
thread:join
added in 3.0
(thread:join)(thread:join thread)(thread:join thread millis)(thread:join thread millis nanos)calls join on a thread
thread:notify-all
added in 3.0
(thread:notify-all lock)notifies all threads waiting on lock
thread:uncaught
added in 3.0
(thread:uncaught)(thread:uncaught thread)(thread:uncaught thread f)gets and sets the uncaught exception handler
transact
added in 3.0
(transact client thunk)enable transactions on client
(->> (transact |client| (fn [] (req |client| {:type :eval :form 1} {:chain #(* 8 %)}))) (map deref))
wrap-min-time
added in 3.0
(wrap-min-time f total)(wrap-min-time f total delay)wraps a function with min-time and delay
((wrap-min-time (fn []) 20 0))
((wrap-min-time (fn []) 100 10))