Skip to content
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

Separate head and pop (allow peeking) #67

Closed
akiross opened this issue Oct 20, 2017 · 3 comments
Closed

Separate head and pop (allow peeking) #67

akiross opened this issue Oct 20, 2017 · 3 comments

Comments

@akiross
Copy link

akiross commented Oct 20, 2017

Hello,
I am using janus, very happily, to mix async and threaded code, and it works great.

I have just a little suggestion about the API: I think you should provide a head() or peek() method, that allows to get the first element in the queue without removing it. Although this is not really necessary (also, you provide a PriorityQueue), I think it's a great addition which could make user code easier.

The current get() method could be implemented using head() + removal, so code should stay reasonably similar to the current.

This would allow to take decisions earlier, without messing with queue order.

@asvetlov
Copy link
Member

It's not very helpful because of concurrent nature: a value returned by peek() could be different from the value from subsequent get() call if the queue has multiple consumers.

Standard queue.Queue and asyncio.Queue have no peek() methods exactly for the same reason.

@akiross
Copy link
Author

akiross commented Oct 20, 2017

You're right! But it's helpful when there is a single consumer :) In my use case, I have multiple producing threads and a single (async) consumer. But I get your point, I'm still happy with janus even if you won't include it.

@asvetlov
Copy link
Member

Unfortunately not -- I'd like to keep janus API in sync with queues from stdlib.

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

No branches or pull requests

2 participants