#1: Fix race conditions errors and rewrite tests

This commit is contained in:
ErickSkrauch
2019-04-19 01:41:52 +03:00
parent e14619e079
commit 8244351bb5
4 changed files with 191 additions and 190 deletions

View File

@@ -25,24 +25,29 @@ func (s *jobsQueue) New() *jobsQueue {
func (s *jobsQueue) Enqueue(t *jobItem) {
s.lock.Lock()
defer s.lock.Unlock()
s.items = append(s.items, t)
s.lock.Unlock()
}
func (s *jobsQueue) Dequeue(n int) []*jobItem {
s.lock.Lock()
defer s.lock.Unlock()
if n > s.Size() {
n = s.Size()
}
items := s.items[0:n]
s.items = s.items[n:len(s.items)]
s.lock.Unlock()
return items
}
func (s *jobsQueue) IsEmpty() bool {
s.lock.Lock()
defer s.lock.Unlock()
return len(s.items) == 0
}