-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use a final class for Queue instances instead of anonymous trait instances
#9763
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,14 +150,22 @@ object Queue extends QueuePlatformSpecific { | |
| shutdownHook: Promise[Nothing, Unit], | ||
| shutdownFlag: AtomicBoolean, | ||
| strategy: Strategy[A] | ||
| ): Queue[A] = new Queue[A] { | ||
| ): Queue[A] = new QueueImpl[A](queue, takers, shutdownHook, shutdownFlag, strategy) | ||
|
|
||
| private final class QueueImpl[A]( | ||
| queue: MutableConcurrentQueue[A], | ||
| takers: ConcurrentDeque[Promise[Nothing, A]], | ||
| shutdownHook: Promise[Nothing, Unit], | ||
| shutdownFlag: AtomicBoolean, | ||
| strategy: Strategy[A] | ||
| ) extends Queue[A] { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why we need to make this change?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better stack traces. That's a kind of change we already made in some other places with Kyri |
||
|
|
||
| private def removeTaker(taker: Promise[Nothing, A])(implicit trace: Trace): UIO[Unit] = | ||
| ZIO.succeed(takers.remove(taker)) | ||
|
|
||
| val capacity: Int = queue.capacity | ||
| override def capacity: Int = queue.capacity | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| def offer(a: A)(implicit trace: Trace): UIO[Boolean] = | ||
| override def offer(a: A)(implicit trace: Trace): UIO[Boolean] = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind it either way, but is there a reason other than readability for adding the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally prefer leaving it off - if someone adds a default implementation, they should get a compiler error.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer adding them. Makes it more explicit. If you differ from the super class or the super has a default value, you get a/the right error message.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, explicitness > implicitness. So yeah it's about readability. So I don't have to guess or to remember that it's overriding something |
||
| ZIO.suspendSucceed { | ||
| if (shutdownFlag.get) ZIO.interrupt | ||
| else { | ||
|
|
@@ -186,7 +194,7 @@ object Queue extends QueuePlatformSpecific { | |
| } | ||
| } | ||
|
|
||
| def offerAll[A1 <: A](as: Iterable[A1])(implicit trace: Trace): UIO[Chunk[A1]] = | ||
| override def offerAll[A1 <: A](as: Iterable[A1])(implicit trace: Trace): UIO[Chunk[A1]] = | ||
| ZIO.suspendSucceed { | ||
| if (shutdownFlag.get) ZIO.interrupt | ||
| else { | ||
|
|
@@ -212,17 +220,17 @@ object Queue extends QueuePlatformSpecific { | |
| } | ||
| } | ||
|
|
||
| def awaitShutdown(implicit trace: Trace): UIO[Unit] = shutdownHook.await | ||
| override def awaitShutdown(implicit trace: Trace): UIO[Unit] = shutdownHook.await | ||
|
|
||
| def size(implicit trace: Trace): UIO[Int] = | ||
| override def size(implicit trace: Trace): UIO[Int] = | ||
| ZIO.suspendSucceed { | ||
| if (shutdownFlag.get) | ||
| ZIO.interrupt | ||
| else | ||
| Exit.succeed(queue.size() - takers.size() + strategy.surplusSize) | ||
| } | ||
|
|
||
| def shutdown(implicit trace: Trace): UIO[Unit] = | ||
| override def shutdown(implicit trace: Trace): UIO[Unit] = | ||
| ZIO.fiberIdWith { fiberId => | ||
| shutdownFlag.set(true) | ||
|
|
||
|
|
@@ -231,9 +239,9 @@ object Queue extends QueuePlatformSpecific { | |
| ) | ||
| }.uninterruptible | ||
|
|
||
| def isShutdown(implicit trace: Trace): UIO[Boolean] = ZIO.succeed(shutdownFlag.get) | ||
| override def isShutdown(implicit trace: Trace): UIO[Boolean] = ZIO.succeed(shutdownFlag.get) | ||
|
|
||
| def take(implicit trace: Trace): UIO[A] = | ||
| override def take(implicit trace: Trace): UIO[A] = | ||
| ZIO.fiberIdWith { fiberId => | ||
| if (shutdownFlag.get) ZIO.interrupt | ||
| else { | ||
|
|
@@ -258,7 +266,7 @@ object Queue extends QueuePlatformSpecific { | |
| } | ||
| } | ||
|
|
||
| def takeAll(implicit trace: Trace): UIO[Chunk[A]] = | ||
| override def takeAll(implicit trace: Trace): UIO[Chunk[A]] = | ||
| ZIO.suspendSucceed { | ||
| if (shutdownFlag.get) | ||
| ZIO.interrupt | ||
|
|
@@ -273,7 +281,7 @@ object Queue extends QueuePlatformSpecific { | |
| } | ||
| } | ||
|
|
||
| def takeUpTo(max: Int)(implicit trace: Trace): UIO[Chunk[A]] = | ||
| override def takeUpTo(max: Int)(implicit trace: Trace): UIO[Chunk[A]] = | ||
| ZIO.suspendSucceed { | ||
| if (shutdownFlag.get) | ||
| ZIO.interrupt | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can merge the Atomic with the Queue to avoid another field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I'm not sure to understand your comment 🤔