Overview

This PR implements the improved Queue shutdown functionality as proposed in #9844. It introduces a dedicated error type E to Queue (via ZQueue) and adds the shutdownCause method, allowing for more robust error propagation and resource disposal during queue shutdown.

Key Changes

  • New Traits and Type Parameters:
    • Introduced ZDequeue[+E, +A], ZEnqueue[+E, -A], and ZQueue[E, A] to support a dedicated error type E.
    • Maintained source compatibility for existing code by defining Dequeue[+A], Enqueue[-A], and Queue[A] as type aliases for the Nothing error case in package.scala.
  • Improved Shutdown Mechanics:
    • Added shutdownCause(cause: Cause[E])(implicit trace: Trace): UIO[Chunk[A]] to ZDequeue, ZEnqueue, and ZQueue.
    • The shutdownCause method is atomic; the first caller “wins” and sets the cause. It also returns all items currently buffered in the queue, allowing for proper resource disposal.
    • Subsequent attempts to interact with the queue (e.g., offer, take, size) will now fail with the specified Cause[E] instead of simply being interrupted.
  • Method Updates:
    • Updated take, offer, takeAll, offerAll, and other core methods to return IO[E, ...] instead of UIO[...].
    • Existing suspended fibers (takers and back-pressured offerors) are now completed with the failure cause when the queue is shut down via shutdownCause.
  • ZStream Integration:
    • Updated ZStream.fromQueue and ZStream.fromQueueWithShutdown to handle the new error type. Streams created from a queue will now fail with the queue’s shutdown cause.
  • Hub Integration:
    • Updated Hub.scala to maintain consistency with the new ZEnqueue and ZDequeue traits.

Verification

  • Added a comprehensive test suite in QueueShutdownCauseSpec.scala covering:
    • Failure of subsequent interactions with the specified cause.
    • Failure of existing suspended fibers with the cause.
    • Retrieval of buffered items during shutdown.
    • Atomicity of shutdownCause.
    • ZStream failure propagation.
  • Verified that existing tests in QueueSpec.scala continue to pass.

/claim #9844

closes: #9844

Claim

Total prize pool $1,100
Total paid $0
Status Pending
Submitted March 13, 2026
Last updated March 13, 2026

Contributors

SU

Supreme Labs

@supreme2580

100%

Sponsors

SU

Supreme Labs

@supreme2580

$1,000
ZI

ZIO

@ZIO

$100