Liking cljdoc? Tell your friends :D

csp-clj.channels.waiters

Internal concurrency primitives for channels.

Provides the Waiter and Commit abstractions used to build atomic multi-channel operations (select!) and standard blocking channel operations on virtual threads.

Internal concurrency primitives for channels.

Provides the Waiter and Commit abstractions used to build
atomic multi-channel operations (select!) and standard blocking
channel operations on virtual threads.
raw docstring

commit-all!clj

(commit-all! q val)

Commits every waiter currently in q with val (best effort; already-completed waiters are discarded), draining the queue. Used by close! to wake all blocked takers/putters.

The caller must hold the channel lock.

Commits every waiter currently in q with val (best effort; already-completed
waiters are discarded), draining the queue. Used by close! to wake all
blocked takers/putters.

The caller must hold the channel lock.
sourceraw docstring

commit-first!clj

(commit-first! q val)

Polls q until it finds a pending waiter, commits it with val, and returns that waiter. Already-completed waiters are discarded. Returns nil if the queue is drained without a successful commit.

The caller must hold the channel lock.

Polls q until it finds a pending waiter, commits it with val, and returns
that waiter. Already-completed waiters are discarded. Returns nil if the
queue is drained without a successful commit.

The caller must hold the channel lock.
sourceraw docstring

EOFclj

source

ICommitStatecljprotocol

get-stateclj

(get-state commit)

set-state!clj

(set-state! commit val)
source

IWaitercljprotocol

commit-valclj

(commit-val waiter val)

Returns the value that should be set in the commit state upon success.

Returns the value that should be set in the commit state upon success.

get-commitclj

(get-commit waiter)

Returns the Commit object associated with this waiter.

Returns the Commit object associated with this waiter.

get-valueclj

(get-value waiter)

Returns the value associated with this waiter. Returns nil for take waiters.

Returns the value associated with this waiter. Returns nil for take waiters.
source

match-putter!clj

(match-putter! puts waiter)

Poll puts until a live putter is matched against the AltsTakeWaiter, and return that putter. Already-completed putters are discarded. Returns nil if the queue is drained.

The caller must hold the channel lock.

Poll puts until a live putter is matched against the AltsTakeWaiter, and
return that putter. Already-completed putters are discarded. Returns nil if
the queue is drained.

The caller must hold the channel lock.
sourceraw docstring

match-taker!clj

(match-taker! takes waiter)

Poll takes until a live taker is matched against the AltsPutWaiter, and return that taker. Already-completed takers are discarded. Returns nil if the queue is drained.

The caller must hold the channel lock.

Poll takes until a live taker is matched against the AltsPutWaiter, and
return that taker. Already-completed takers are discarded. Returns nil if
the queue is drained.

The caller must hold the channel lock.
sourceraw docstring

new-commitclj

(new-commit)

Creates a new Commit object for the current thread.

The Commit captures:

  • Thread ID: Used for lock ordering in try-match! (deadlock prevention)
  • Thread reference: Used by LockSupport/unpark to wake this thread
  • State: Initially nil (pending), set to result when completed

Returns: Commit instance with nil state, ready for park-and-wait

Creates a new Commit object for the current thread.

The Commit captures:
- Thread ID: Used for lock ordering in try-match! (deadlock prevention)
- Thread reference: Used by LockSupport/unpark to wake this thread
- State: Initially nil (pending), set to result when completed

Returns:
  Commit instance with nil state, ready for park-and-wait
sourceraw docstring

park-and-waitclj

(park-and-wait commit timeout-ms)

Parks the current virtual thread until the commit state is no longer nil.

Handles timeouts and Thread/interrupts correctly. If a timeout occurs or the thread is interrupted, attempts to lock the commit and set the state to :timeout or :interrupted respectively.

Returns the final state of the commit.

Parks the current virtual thread until the commit state is no longer nil.

Handles timeouts and Thread/interrupts correctly.
If a timeout occurs or the thread is interrupted, attempts to lock the
commit and set the state to :timeout or :interrupted respectively.

Returns the final state of the commit.
sourceraw docstring

poll!clj

(poll! q)

Extracts and removes the first element from a queue.

Wrapper around java.util.Queue/poll for type hinting. Returns nil if the queue is empty.

Used to atomically retrieve and remove waiters from takes/puts queues while holding the channel lock.

Extracts and removes the first element from a queue.

Wrapper around java.util.Queue/poll for type hinting.
Returns nil if the queue is empty.

Used to atomically retrieve and remove waiters from takes/puts queues
while holding the channel lock.
sourceraw docstring

PUT_FAILclj

source

try-commit!clj

(try-commit! waiter val)

Atomically attempt to fulfill a single waiter. Acquires the commit monitor lock. Returns true if successful.

Atomically attempt to fulfill a single waiter.
Acquires the commit monitor lock. Returns true if successful.
sourceraw docstring

try-commit-with!clj

(try-commit-with! waiter f x)

Like try-commit! but computes the committed value as (f x). (f x) is only evaluated if the commit is still pending, so callers do not need to allocate a thunk.

The caller must hold the channel lock.

Like try-commit! but computes the committed value as (f x). (f x) is only
evaluated if the commit is still pending, so callers do not need to allocate
a thunk.

The caller must hold the channel lock.
sourceraw docstring

try-match!clj

(try-match! w1 w2 val)

Atomically attempt to fulfill two waiters simultaneously. Acquires both commit locks in ID order to prevent deadlocks. Returns true if BOTH commits were successfully fulfilled.

Atomically attempt to fulfill two waiters simultaneously.
Acquires both commit locks in ID order to prevent deadlocks.
Returns true if BOTH commits were successfully fulfilled.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close