I am using a thread-pool example from http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/ and I am following that tutorial however I am getting this error on compile d.pool undefined (type *Dispatcher has no field or method pool) this is the code
type Dispatcher struct {
// A pool of workers channels that are registered with the dispatcher
WorkerPool chan chan Job
}
func NewWorker(workerPool chan chan Job) Worker {
return Worker{
WorkerPool: workerPool,
JobChannel: make(chan Job),
quit: make(chan bool)}
}
func NewDispatcher(maxWorkers int) *Dispatcher {
pool := make(chan chan Job, maxWorkers)
return &Dispatcher{WorkerPool: pool}
}
func (d *Dispatcher) Run() {
// starting n number of workers
//d.WorkerPool
for i := 0; i < 5; i++ {
worker := NewWorker(d.pool)
worker.Start()
}
go d.dispatch()
}
The error is happening with this code
worker := NewWorker(d.pool)
Any solutions or suggestions would be great as I am new to this but am trying to implement a thread pool
The error means exactly what it says, your Dispatcher
type has no field or method named pool
. It does, however, have a field named WorkerPool
, which is what I'm guessing you meant to reference.