@std/queues.ms#
Import each required symbol with import Name from "@std/queues.ms".
BlockingQueue Native type#
A FIFO queue that waits instead of failing: put blocks while a bounded queue is full, and take blocks while the queue is empty. It synchronizes itself, so tasks share it directly. Waiting stops at cancellation, so a TaskGroup close unblocks every waiting task.
type BlockingQueue[T]:
capacity: Optional[Int] = none
fn put(value: T) -> Bool:
fn take() -> Optional[T]:
fn close() -> Unit:
fn length() -> Int:
fn is_closed() -> Bool:BlockingQueue.capacity#
Constructor capacity in items; omission/none is unbounded, and supplied values must be positive.
capacity: Optional[Int] = noneBlockingQueue.close#
Closes the queue and wakes every waiting task. Queued values can still be taken; later puts return false.
fn close() -> Unit:BlockingQueue.is_closed#
Reports whether close has been called.
fn is_closed() -> Bool:BlockingQueue.length#
Returns the number of values currently waiting in the queue.
fn length() -> Int:BlockingQueue.put#
Waits for free space, then adds the value and returns true. Returns false when the queue is closed.
fn put(value: T) -> Bool:BlockingQueue.take#
Waits for a value and removes the oldest. Returns none once the queue is closed and empty.
fn take() -> Optional[T]:PriorityQueue Native type#
Negative compare results put left before right; equal priorities remain FIFO.
type PriorityQueue[T]:
compare: fn(left: T, right: T) -> Int
capacity: Optional[Int] = none
fn enqueue(value: T) -> Bool:
fn dequeue() -> Optional[T]:
fn peek() -> Optional[T]:
fn length() -> Int:
fn is_empty() -> Bool:PriorityQueue.capacity#
Constructor capacity in items; omission/none is unbounded, and supplied values must be positive.
capacity: Optional[Int] = nonePriorityQueue.compare#
Constructor comparator: negative puts left first; ties dequeue in enqueue order. Comparisons must stay consistent and must not mutate this queue.
compare: fn(left: T, right: T) -> IntPriorityQueue.dequeue#
Removes and returns the next value by priority, or none when empty.
fn dequeue() -> Optional[T]:PriorityQueue.enqueue#
Adds a value, returning false when a bounded queue is full.
fn enqueue(value: T) -> Bool:PriorityQueue.is_empty#
Reports whether the queue has no values to peek or dequeue.
fn is_empty() -> Bool:PriorityQueue.length#
Returns the number of enqueued values, independent of their priorities.
fn length() -> Int:PriorityQueue.peek#
Returns the next value by priority without removing it, or none when empty.
fn peek() -> Optional[T]:Queue Native type#
A local mutable FIFO queue; protect all shared access with Synchronized. Omitted or none capacity grows as needed and adds no fixed queue limit.
type Queue[T]:
capacity: Optional[Int] = none
fn enqueue(value: T) -> Bool:
fn dequeue() -> Optional[T]:
fn peek() -> Optional[T]:
fn length() -> Int:
fn is_empty() -> Bool:Queue.capacity#
Constructor capacity in items; omission/none is unbounded, and supplied values must be positive.
capacity: Optional[Int] = noneQueue.dequeue#
Removes and returns the oldest value, or none when empty.
fn dequeue() -> Optional[T]:Queue.enqueue#
Adds a value, returning false when a bounded queue is full.
fn enqueue(value: T) -> Bool:Queue.is_empty#
Reports whether dequeue and peek would return none.
fn is_empty() -> Bool:Queue.length#
Returns the number of values currently waiting in the queue.
fn length() -> Int:Queue.peek#
Returns the oldest value without removing it, or none when the queue is empty.
fn peek() -> Optional[T]: