amuz.es/src/infra/goutils@v0.1.3/async/iface_queue.go (about) 1 package async 2 3 import ( 4 "container/list" 5 ) 6 7 // 블럭되지 않는 큐체널 8 func NewQueue() (chan<- interface{}, <-chan interface{}) { 9 send := make(chan interface{}, 1) 10 receive := make(chan interface{}, 1) 11 go manageQueue(send, receive) 12 return send, receive 13 } 14 15 func manageQueue(send <-chan interface{}, receive chan<- interface{}) { 16 queue := list.New() 17 defer close(receive) 18 for { 19 if front := queue.Front(); front == nil { 20 if value, ok := <-send; ok { 21 queue.PushBack(value) 22 } else { 23 break 24 } 25 } else { 26 select { 27 case receive <- front.Value: 28 queue.Remove(front) 29 case value, ok := <-send: 30 if ok { 31 queue.PushBack(value) 32 } 33 } 34 } 35 } 36 }