func (q *queue) Stop() {
	q.mutex.Lock()
	defer q.mutex.Unlock()
	if q.status != queueStopped {
		close(q.kill)
		q.status = queueStopped
	}
}
Stop closes both Err and Event channels, and
causes the handling loop to exit.
package scheduler
import (
	"errors"
	"sync"
)
var (
	errQueueEmpty    = errors.New("queue empty")
	errLimitExceeded = errors.New("limit exceeded")
)
type jobHandler func(queuedJob)
type queue struct {
	Event chan queuedJob
	Err   chan *queuingError
	handler jobHandler
	limit   uint
	kill    chan struct{}
	items   []queuedJob
	mutex   *sync.Mutex
	status  queueStatus
}
type queueStatus int
const (
	queueStopped queueStatus = iota  
	queueRunning                     
	queueWorking                     
)
type queuingError struct {
	Job job
	Err error
}
func (qe *queuingError) Error() string {
	return qe.Err.Error()
}
func newQueue(limit uint, handler jobHandler) *queue {
	return &queue{
		Event: make(chan queuedJob),
		Err:   make(chan *queuingError),
		handler: handler,
		limit:   limit,
		kill:    make(chan struct{}),
		items:   []queuedJob{},
		mutex:   &sync.Mutex{},
		status:  queueStopped,
	}
}
func (q *queue) Start() {
	q.mutex.Lock()
	defer q.mutex.Unlock()
	if q.status == queueStopped {
		q.status = queueRunning
		go q.start()
	}
}