worker semantics change

slack
Jordan Orelli 10 years ago
parent 47f9dfd8de
commit de28dc142d

@ -58,22 +58,24 @@ func After(delay time.Duration, work func()) {
func RunQueue() { func RunQueue() {
defer log_info("Queue runner done.") defer log_info("Queue runner done.")
heap.Init(&queue) heap.Init(&queue)
ticker := time.Tick(10 * time.Millisecond)
for { for {
if len(queue) == 0 { select {
time.Sleep(10 * time.Microsecond) case <-ticker:
continue if queue.Len() == 0 {
break
} }
queueLock.Lock()
future, ok := heap.Pop(&queue).(*Future) future, ok := heap.Pop(&queue).(*Future)
queueLock.Unlock()
if !ok { if !ok {
log_error("there's shit on the work heap") log_error("there's shit on the work heap")
continue break
}
if future.ts.After(time.Now()) {
time.Sleep(future.ts.Sub(time.Now()))
} }
if future.ts.Before(time.Now()) {
future.work() future.work()
} else {
heap.Push(&queue, future)
}
}
} }
} }

Loading…
Cancel
Save