func (d *Dispatcher) CleanUnperformedJobs() {
	d.unperformedJobs = make([]GoJob, 0)
}
CleanUnperformedJobs remove unperformedJobs
package goworker
import (
	"sync"
	"time"
)
type Dispatcher struct {
	WorkerPool      chan chan GoJob
	Workers         chan *Worker
	maxWorkers      int
	jobsQueue       chan GoJob
	unperformedJobs []GoJob
	stop            chan bool
	stopped         chan bool
	wg              *sync.WaitGroup
	stopInProgress  bool
}
func NewDispatcher(maxWorkers int, jobsQueueSize uint) *Dispatcher {
	jobsQueue := make(chan GoJob, jobsQueueSize)
	var unperformedJobs []GoJob  
	pool := make(chan chan GoJob, maxWorkers)
	workers := make(chan *Worker, maxWorkers)
	return &Dispatcher{
		WorkerPool:      pool,
		Workers:         workers,
		maxWorkers:      maxWorkers,
		jobsQueue:       jobsQueue,
		unperformedJobs: unperformedJobs,
		stop:            make(chan bool, 1),
		stopped:         make(chan bool, 1),
		wg:              &sync.WaitGroup{},
		stopInProgress:  false,
	}
}
func (d *Dispatcher) Run() {
	d.CleanUnperformedJobs()
	for i := 0; i < d.maxWorkers; i++ {
		w := NewWorker(i, d.WorkerPool)
		w.Start(d.wg)
		d.Workers <- w
	}
	d.dispatch()
}
func (d *Dispatcher) dispatch() {
	defer func() {
		d.stopWorkers()
		d.wg.Wait()
		if len(d.jobsQueue) > 0 {
			for j := range d.jobsQueue {
				d.unperformedJobs = append(d.unperformedJobs, j)
				if len(d.jobsQueue) == 0 {
					break
				}
			}
		}
		d.stopInProgress = false
		d.stopped <- true
	}()
	for {
		select {
		case job := <-d.jobsQueue:
			select {
			case jobChannel := <-d.WorkerPool:
				jobChannel <- job
			case <-d.stop:
				d.unperformedJobs = append(d.unperformedJobs, job)
				return
			}
		case <-d.stop:
			return
		}
	}
}
func (d *Dispatcher) stopWorkers() {
	defer func() {
		for _ = range d.WorkerPool {
			if len(d.WorkerPool) == 0 {
				return
			}
		}
	}()
	for w := range d.Workers {
		w.Stop()
		if len(d.Workers) == 0 {
			return
		}
	}
}
func (d *Dispatcher) AddJob(job GoJob) {
	for {
		if d.stopInProgress == false {
			d.jobsQueue <- job
			break
		}
		time.Sleep(time.Microsecond)
	}
}
func (d *Dispatcher) Stop() {
	d.stopInProgress = true
	d.stop <- true
	<-d.stopped
}
func (d *Dispatcher) GetUnperformedJobs() []GoJob {
	return d.unperformedJobs
}