forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
netOutMsgQueue.go
48 lines (40 loc) · 1.14 KB
/
netOutMsgQueue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package state
import (
"github.com/FactomProject/factomd/common/interfaces"
)
// NetOutMsgQueue counts incoming and outgoing messages for netout queue
type NetOutMsgQueue chan interfaces.IMsg
func NewNetOutMsgQueue(capacity int) NetOutMsgQueue {
channel := make(chan interfaces.IMsg, capacity)
return channel
}
// Length of underlying channel
func (q NetOutMsgQueue) Length() int {
return len(chan interfaces.IMsg(q))
}
// Cap of underlying channel
func (q NetOutMsgQueue) Cap() int {
return cap(chan interfaces.IMsg(q))
}
// Enqueue adds item to channel and instruments based on type
func (q NetOutMsgQueue) Enqueue(m interfaces.IMsg) {
measureMessage(TotalMessageQueueNetOutMsgGeneralVec, m, true)
q <- m
}
// Dequeue removes an item from channel and instruments based on type. Returns nil if nothing in
// queue
func (q NetOutMsgQueue) Dequeue() interfaces.IMsg {
select {
case v := <-q:
//NetOutMsgQueueRateKeeper.Complete()
return v
default:
return nil
}
}
// BlockingDequeue will block until it retrieves from queue
func (q NetOutMsgQueue) BlockingDequeue() interfaces.IMsg {
v := <-q
//NetOutMsgQueueRateKeeper.Complete()
return v
}