func (q *Queue) Submit(tasks ...func()) error {
	if err := q.appendQueue(tasks); err != nil {
		return err
	}
	_ = q.goPool.Submit(func() {
		for {
			task := q.popQueue()
			if task == nil {
				return
			}
			task()
		}
	})
	return nil
}
Submit appends and execute task by Queue.
package queue
import (
	"container/list"
	"fmt"
	"sync"
	"github.com/panjf2000/ants/v2"
)
type Queue struct {
	goPool *ants.Pool
	limit  int
	mutex sync.Mutex
	queue *list.List
}
func New(cfg Config) (*Queue, error) {
	if cfg.Size <= 0 {
		return nil, fmt.Errorf("invalid value of Size")
	}
	p, err := ants.NewPool(cfg.GoPoolSize, ants.WithPreAlloc(true), ants.WithExpiryDuration(cfg.MaxIdleTime), ants.WithNonblocking(true))
	if err != nil {
		return nil, err
	}
	return &Queue{
		queue:  list.New(),
		goPool: p,
		limit:  cfg.Size,
	}, nil
}
func (q *Queue) appendQueue(tasks []func()) error {
	q.mutex.Lock()
	defer q.mutex.Unlock()
	if q.queue.Len()+len(tasks) > q.limit {
		return fmt.Errorf("reached limit of max processed jobs")
	}
	for _, t := range tasks {
		q.queue.PushBack(t)
	}
	return nil
}
func (q *Queue) popQueue() func() {
	q.mutex.Lock()
	defer q.mutex.Unlock()
	if q.queue.Len() == 0 {
		return nil
	}
	return q.queue.Remove(q.queue.Front()).(func())
}