패키지이동
This commit is contained in:
parent
5e63a2b446
commit
b15525f489
|
@ -1,4 +1,4 @@
|
|||
package buf
|
||||
package async
|
||||
|
||||
import (
|
||||
"container/list"
|
|
@ -0,0 +1,36 @@
|
|||
package async
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
)
|
||||
|
||||
// 블럭되지 않는 큐체널
|
||||
func NewQueue() (chan<- interface{}, <-chan interface{}) {
|
||||
send := make(chan interface{}, 1)
|
||||
receive := make(chan interface{}, 1)
|
||||
go manageQueue(send, receive)
|
||||
return send, receive
|
||||
}
|
||||
|
||||
func manageQueue(send <-chan interface{}, receive chan<- interface{}) {
|
||||
queue := list.New()
|
||||
defer close(receive)
|
||||
for {
|
||||
if front := queue.Front(); front == nil {
|
||||
if value, ok := <-send; ok {
|
||||
queue.PushBack(value)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
select {
|
||||
case receive <- front.Value.(interface{}):
|
||||
queue.Remove(front)
|
||||
case value, ok := <-send:
|
||||
if ok {
|
||||
queue.PushBack(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package buf
|
||||
package async
|
||||
|
||||
import (
|
||||
"container/list"
|
Reference in New Issue