Fix race condition error

This commit is contained in:
ErickSkrauch 2020-01-03 01:04:23 +03:00
parent 5a0c10c1a1
commit 7f9b60ab3a

View File

@ -41,8 +41,8 @@ func (s *jobsQueue) Dequeue(n int) []*jobItem {
s.lock.Lock()
defer s.lock.Unlock()
if n > s.Size() {
n = s.Size()
if n > s.size() {
n = s.size()
}
items := s.items[0:n]
@ -52,6 +52,13 @@ func (s *jobsQueue) Dequeue(n int) []*jobItem {
}
func (s *jobsQueue) Size() int {
s.lock.Lock()
defer s.lock.Unlock()
return s.size()
}
func (s *jobsQueue) size() int {
return len(s.items)
}