728x90
반응형
package channel
import (
"fmt"
"math/rand"
)
const QUEUE_SIZE = 20
var queue = newChannelQueue(QUEUE_SIZE)
type ChannelQueue struct {
data chan any
}
func newChannelQueue(size int) *ChannelQueue {
return &ChannelQueue{
data: make(chan any, size),
}
}
func (q *ChannelQueue) get() any {
return <-q.data
}
func (q *ChannelQueue) set(value any) {
q.data <- value
}
func setTest() {
queue.set(rand.Intn(10))
}
func getTest() any {
return queue.get()
}
func ChannelQueueMain() {
setTest()
fmt.Println(getTest())
setTest()
fmt.Println(getTest())
setTest()
fmt.Println(getTest())
setTest()
setTest()
setTest()
setTest()
setTest()
setTest()
setTest()
fmt.Println(getTest())
}
728x90
반응형
'Go' 카테고리의 다른 글
[Go] Time (0) | 2022.08.02 |
---|---|
[Go] Factory Pattern(팩토리 패턴) 구현 (0) | 2022.07.25 |
[Go] Int, String, Struct 정렬 (0) | 2022.07.23 |
[Go] Linked List 구현 (0) | 2022.07.23 |
[Go] Panic recover 하기 (0) | 2022.07.23 |