Liking cljdoc? Tell your friends :D

bites.exchange


exchange!clj

(exchange! e x)
(exchange! e x timeout-ms)
source

start-consuming-fromclj

(start-consuming-from q consume!)

An endless (unless thread interrupted) consuming loop for this given queue. consume! must be a 1-arg fn.

An endless (unless thread interrupted)
consuming loop for this given queue.
`consume!` must be a 1-arg fn.
sourceraw docstring

start-producing-intoclj

(start-producing-into q produce!)

An endless (unless thread interrupted) producing loop for this given queue. produce! must be a no-arg fn.

An endless (unless thread interrupted)
producing loop for this given queue.
`produce!` must be a no-arg fn.
sourceraw docstring

with-blocking-queue!clj

(with-blocking-queue! produce! consume!)
(with-blocking-queue! buffer produce! consume!)

The opposite of with-sync-exchange in terms of semantics (i.e. synchronous/bi-directional VS asynchronous/one-directional). The benefit here is that multiple producers/consumers are supported. Default queue is a fair ArrayBlockingQueue with capacity 1024, which should exhibit very similar memory allocation characteristics with a with-sync-exchange call (with default buffer). Returns a vector of two seqs (the producing/consuming futures in the same order as the provided producing/consuming fns).

The opposite of `with-sync-exchange` in terms of semantics
(i.e. synchronous/bi-directional VS asynchronous/one-directional).
The benefit here is that multiple producers/consumers are supported.
Default queue is a fair `ArrayBlockingQueue` with capacity 1024,
which should exhibit very similar memory allocation characteristics
with a `with-sync-exchange` call (with default buffer).
Returns a vector of two seqs (the producing/consuming futures in
the same order as the provided producing/consuming fns).
sourceraw docstring

with-sync-exchange!clj

(with-sync-exchange! produce! consume!)
(with-sync-exchange! buffer produce! consume!)

Given a producing-fn, and a consuming-fn (both 1-arg), assign each its own thread and object-array of size <buffer>, and has them exchanging arrays when they're BOTH ready (i.e. their respective operation exhausted the array it was working with). During the initial producing, the producing-fn must be able to deal with nils. Returns a vector of two futures (representing the producing/consuming loops). Cancelling either stops its internal loop. A slow consumer will (eventually) block a faster producer, so a non-blocking consuming-fn would be ideal. Unlike using a typical data-structure, this kind of data-exchange between two threads is allocation-free (but synchronous). See java.util.concurrent.Exchanger for the core idea, and the underlying construct this is implemented on top of.

Given a producing-fn, and a consuming-fn (both 1-arg),
assign each its own thread and object-array of size <buffer>,
and has them exchanging arrays when they're BOTH ready
(i.e. their respective operation exhausted the array it was working with).
During the initial producing, the producing-fn must be able to deal with nils.
Returns a vector of two futures (representing the producing/consuming loops).
Cancelling either stops its internal loop. A slow consumer will (eventually)
block a faster producer, so a non-blocking consuming-fn would be ideal.
Unlike using a typical data-structure, this kind of data-exchange between two
threads is allocation-free (but synchronous). See `java.util.concurrent.Exchanger`
for the core idea, and the underlying construct this is implemented on top of.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close