package domain import ( "container/list" "sync" ) type QueueX struct { locker *sync.RWMutex dataLst *list.List } func NewQueue() *QueueX { return &QueueX{ locker: new(sync.RWMutex), dataLst: list.New(), } } func (q *QueueX) Push(v interface{}) { q.locker.Lock() defer q.locker.Unlock() q.dataLst.PushBack(v) } func (q *QueueX) Pop() interface{} { q.locker.Lock() defer q.locker.Unlock() if e := q.dataLst.Front(); e != nil { v := q.dataLst.Remove(e) return v } return nil } func (q *QueueX) Empty() bool { q.locker.RLock() defer q.locker.RUnlock() return q.dataLst.Len() == 0 }