forked from asynkron/protoactor-go
/
unbounded.go
38 lines (33 loc) · 846 Bytes
/
unbounded.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
package mailbox
import (
"github.com/AsynkronIT/protoactor-go/internal/queue/goring"
"github.com/AsynkronIT/protoactor-go/internal/queue/mpsc"
)
type unboundedMailboxQueue struct {
userMailbox *goring.Queue
}
func (q *unboundedMailboxQueue) Push(m interface{}) {
q.userMailbox.Push(m)
}
func (q *unboundedMailboxQueue) Pop() interface{} {
m, o := q.userMailbox.Pop()
if o {
return m
}
return nil
}
// Unbounded returns a producer which creates an unbounded mailbox
func Unbounded(mailboxStats ...Statistics) Producer {
return func(invoker MessageInvoker, dispatcher Dispatcher) Inbound {
q := &unboundedMailboxQueue{
userMailbox: goring.New(10),
}
return &defaultMailbox{
systemMailbox: mpsc.New(),
userMailbox: q,
invoker: invoker,
mailboxStats: mailboxStats,
dispatcher: dispatcher,
}
}
}