8000 Enqueue+Dequeue: add `shutdownCause` method by hearnadam · Pull Request #9928 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enqueue+Dequeue: add shutdownCause method #9928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: series/2.x
Choose a base branch
from
Draft

Conversation

hearnadam
Copy link
Collaborator

/claim #9844

  • implement method for Hub and Queue

val capacity: Int =
hub.capacity
def isShutdown(implicit trace: Trace): UIO[Boolean] =
ZIO.succeed(shutdownFlag.get)
def publish(a: A)(implicit trace: Trace): UIO[Boolean] =
ZIO.suspendSucceed {
if (shutdownFlag.get) ZIO.interrupt
if (shutdownFlag.get) interrupted
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could actually unify on the shutdownHook being the single atomic for this class. Checking promise.unsafe.isDone...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I actually thought about doing that in the past as well. Not sure why I didn't do it 🤔

- implement method for `Hub` and `Queue`
@@ -161,14 +167,16 @@ object Queue extends QueuePlatformSpecific {
strategy: Strategy[A]
) extends Queue[A] {

private def interrupted(implicit trace: Trace): UIO[Nothing] = shutdownHook.await *> ZIO.interrupt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If shutdownHook was fulfilled with an interruption then we don't need the *> ZIO.interrupt (AFAICT)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't typecheck, but yes

* Shuts down the Dequeue with a specific Cause, either `Die` or `Interrupt`.
* Future calls to `take*` fail immediately.
*/
def shutdownCause(cause: Cause[Nothing])(implicit trace: Trace): UIO[Unit] = shutdown(trace)
Copy link
Contributor
@mberndt123 mberndt123 Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the original ticket says:

shutdownCause would also return the items currently buffered in the queue in order to dispose of them

Do you plan to implement that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0