-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add peek to AsyncQueue #557
base: master
Are you sure you want to change the base?
Conversation
chronos/asyncsync.nim
Outdated
@@ -377,6 +444,11 @@ proc get*[T](aq: AsyncQueue[T]): Future[T] {. | |||
## Alias of ``popFirst()``. | |||
aq.popFirst() | |||
|
|||
proc peak*[T](aq: AsyncQueue[T]): Future[T] {. |
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.
proc peak*[T](aq: AsyncQueue[T]): Future[T] {. | |
proc peek*[T](aq: AsyncQueue[T]): Future[T] {. |
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.
My bad, will fix the spelling shortly.
q.putNoWait(1) | ||
q.putNoWait(2) | ||
|
||
check: |
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.
there needs to be a test here that ensures that the following also works:
let a = q.peekFirst()
let b = q.popFirst()
both in that order and in the reverse order - where peek-after-pop should probably not trigger
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've added more tests as suggested.
In some of my code I found the need to do something like this:
Having an async peek proc that waits for the first item to be added to the queue would be good. The std/deques supports peekFirst and peekLast as well so this PR adds these to the AsyncQueue.