8000 Use a final class for `Queue` instances instead of anonymous trait instances by guizmaii · Pull Request #9763 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

guizmaii
Copy link
Member
@guizmaii guizmaii commented Apr 8, 2025

No description provided.

@guizmaii guizmaii marked this pull request as draft April 8, 2025 08:33

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
Copy link
Member Author

Choose a reason for hiding this comment

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

queue.capacity is already a val. We don't need a val here too

@guizmaii guizmaii marked this pull request as ready for review April 8, 2025 11:29
@guizmaii guizmaii self-assigned this Apr 8, 2025
@guizmaii guizmaii changed the title Use a proper final class for Queue instances instead of anonymous trait instances Use a final class for Queue instances instead of anonymous trait instances Apr 8, 2025
Copy link
Contributor
@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

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

LGTM just some minor comments

): Queue[A] = new Queue[A] {
): Queue[A] = new QueueImpl[A](queue, takers, shutdownHook, shutdownFlag, strategy)

final class QueueImpl[A] private[Queue] (
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the class private?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I didn't make it private because I was worried it would make the class leak its private scope. That's why I made the constructor private and not the class. But the compiler isn't complaining so I guess it's fine to make it private


def offer(a: A)(implicit trace: Trace): UIO[Boolean] =
override def offer(a: A)(implicit trace: Trace): UIO[Boolean] =
Copy link
Contributor

Choose a reason for hiding this comment

The 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 override keyword?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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

shutdownHook: Promise[Nothing, Unit],
shutdownFlag: AtomicBoolean,
strategy: Strategy[A]
) extends Queue[A] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain why we need to make this change?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

queue: MutableConcurrentQueue[A],
takers: ConcurrentDeque[Promise[Nothing, A]],
shutdownHook: Promise[Nothing, Unit],
shutdownFlag: AtomicBoolean,
Copy link
Collaborator

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.

Copy link
Member Author

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 🤔

@guizmaii guizmaii merged commit 68f1095 into series/2.x Apr 9, 2025
18 checks passed
@guizmaii guizmaii deleted the proper_queue_class branch April 9, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0