amuz.es/src/infra/goutils@v0.1.3/async/bytes_queue.go (about) 1 package async 2 3 import ( 4 "container/list" 5 ) 6 7 // 블럭되지 않는 큐체널 8 func NewBytesQueue() (chan<- []byte, <-chan []byte) { 9 send := make(chan []byte, 1) 10 receive := make(chan []byte, 1) 11 go manageBytesQueue(send, receive) 12 return send, receive 13 } 14 15 func manageBytesQueue(send <-chan []byte, receive chan<- []byte) { 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.([]byte): 28 queue.Remove(front) 29 case value, ok := <-send: 30 if ok { 31 queue.PushBack(value) 32 } 33 } 34 } 35 } 36 }