You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently I'm just polling in a loop, but I guess in the empty-queue case its lightweight enough: q.RLock() then q.getItemByID(...) => q.Length() => q.tail - q.head, so basically just a lock and a comparison
If it makes the use case easier. I am writing/enqueing from multiple places but only reading/dequeing from one place. I don't mind spurious wakeups and I don't need to race against other goroutines which could also be waiting - I just want to block until the queue is not empty.
Many thanks
func foo(q *goque.Queue) {
ticker := time.NewTicker(pollPeriod)
defer ticker.Stop()
for {
select {
case <-ticker.C: // blocks
}
item, err := q.Peek()
if err == goque.ErrEmpty { continue }
if err != nil { panic(err) }
fmt.Println(item.ToString())
}
}
func main() {
// ...
go foo(q)
// ...
}
The text was updated successfully, but these errors were encountered:
Is it possible to block on peek or pop?
Currently I'm just polling in a loop, but I guess in the empty-queue case its lightweight enough:
q.RLock()
thenq.getItemByID(...)
=>q.Length()
=>q.tail - q.head
, so basically just a lock and a comparisonIf it makes the use case easier. I am writing/enqueing from multiple places but only reading/dequeing from one place. I don't mind spurious wakeups and I don't need to race against other goroutines which could also be waiting - I just want to block until the queue is not empty.
Many thanks
The text was updated successfully, but these errors were encountered: