fljdin/dispatch

Unwanted 100% CPU processus

Closed this issue · 0 comments

The main worker's loop is wrong with a default entry. The queue.Pop() should be called by another goroutine, like observer, to consume any new task from a chanel instead of defaulting an action.

func (w *Worker) Start() {
	w.memory.StartWorker()
	defer w.memory.EndWorker()

	for {
		select {
		case <-w.context.Done():
			return
		default:
			if task, ok := w.memory.queue.Pop(); ok {
				w.handle(task)
			}
		}
	}
}

Possibles solutions: