Skip to content

Std.Queue

effect Queue[A]

Values of type A in order, up to a capacity. dbg shows the capability as <queue>.

  • suspend fn offer(value: A) -> () fails QueueClosed

    Adds value at the end. Waits while the queue is full. Fails with QueueClosed if the queue is closed, or is closed while this waits; the value is then not added.

  • suspend fn take() -> A fails QueueClosed

    Removes the value at the front and returns it. Waits while the queue is empty. Fails with QueueClosed once the queue is closed and empty.

  • fn try_offer(value: A) -> Bool

    Adds value and returns True if the queue is neither full nor closed. Otherwise returns False and adds nothing. Does not suspend.

  • fn poll() -> Option[A]

    Removes the value at the front and returns it as Some, or returns None if the queue is empty. Does not suspend.

  • fn size() -> Int

    The number of values in the queue.

  • fn close() -> ()

    Closes the queue. The values in it can still be taken. Closing a closed queue does nothing.

handler Queue[A]: Queue[A]
init(capacity: Int)

Makes an empty queue that holds up to capacity values. capacity less than 1 is a defect. Its release does nothing.

error QueueClosed

The queue is closed (and, for take, empty).