Abort inside queue instead of counter
This commit is contained in:
parent
707a61d134
commit
1c62c6839b
11
counter.go
11
counter.go
|
@ -16,8 +16,8 @@ type (
|
|||
// If WriteIndex is greater than ReadIndex then there are unread messages
|
||||
// If WriteIndex is less tham ReadIndex then MaxIndex was reached
|
||||
|
||||
Read chan uint
|
||||
mutex sync.Mutex
|
||||
stream chan uint
|
||||
streaming *sync.Cond
|
||||
}
|
||||
)
|
||||
|
@ -48,15 +48,6 @@ func (c *Counter) Write(proc func(i uint) bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Counter) Read(abort chan bool) uint {
|
||||
select {
|
||||
case i := <-c.stream:
|
||||
return i
|
||||
case <-abort:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Counter) Distance() uint {
|
||||
d := c.WriteIndex - c.ReadIndex
|
||||
if d < 0 {
|
||||
|
|
10
queue.go
10
queue.go
|
@ -36,9 +36,15 @@ func (q *Queue) TryFetch(abort chan bool) (Message, bool) {
|
|||
}
|
||||
|
||||
func (q *Queue) Fetch(abort chan bool) (Message, bool) {
|
||||
i := q.Counter.Read(abort)
|
||||
key := NewKey(q.Name, i)
|
||||
var i uint
|
||||
|
||||
select {
|
||||
case i = <-q.Counter.Read:
|
||||
case <-abort:
|
||||
return Message{}, false
|
||||
}
|
||||
|
||||
key := NewKey(q.Name, i)
|
||||
msg, err := storage.Get(key)
|
||||
if err != nil {
|
||||
Error(err, "Failed to read record '%s'", key)
|
||||
|
|
Loading…
Reference in New Issue