nsqio / go-diskqueue

A Go package providing a filesystem-backed FIFO queue
MIT License
467 stars 101 forks source link

Add PeekChan function #24

Closed StoneYunZhao closed 3 years ago

StoneYunZhao commented 3 years ago

As described in #6 , we want to read the first element of the queue but not dequeued.

Here is pseudocode for some peek case.

for <condition> {
  if test(<- dq.PeekChan()) {
    <-dq.ReadChan() // move to next element
  }
}

func test(buf []byte) bool {
  // maybe send to remote
  // or run a long time job which should retry if failed
}
mreiferson commented 3 years ago

Thanks for the PR, this seems reasonable to me.

ploxiln commented 3 years ago

@StoneYunZhao can you rebase on latest master?

StoneYunZhao commented 3 years ago

@StoneYunZhao can you rebase on latest master?

Done.

ploxiln commented 3 years ago

uh, that rebase went wrong somehow, maybe I can fix it ...

ploxiln commented 3 years ago

(ah, you fixed it, thanks)

StoneYunZhao commented 3 years ago

uh, that rebase went wrong somehow, maybe I can fix it ...

Sorry, I tried to fix it, is it okay now?