github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/unbounded.go (about)

     1  package actor
     2  
     3  import (
     4  	"github.com/asynkron/protoactor-go/internal/queue/goring"
     5  	"github.com/asynkron/protoactor-go/internal/queue/mpsc"
     6  )
     7  
     8  type unboundedMailboxQueue struct {
     9  	userMailbox *goring.Queue
    10  }
    11  
    12  func (q *unboundedMailboxQueue) Push(m interface{}) {
    13  	q.userMailbox.Push(m)
    14  }
    15  
    16  func (q *unboundedMailboxQueue) Pop() interface{} {
    17  	m, o := q.userMailbox.Pop()
    18  	if o {
    19  		return m
    20  	}
    21  
    22  	return nil
    23  }
    24  
    25  // Unbounded returns a producer which creates an unbounded mailbox
    26  func Unbounded(mailboxStats ...MailboxMiddleware) MailboxProducer {
    27  	return func() Mailbox {
    28  		q := &unboundedMailboxQueue{
    29  			userMailbox: goring.New(10),
    30  		}
    31  
    32  		return &defaultMailbox{
    33  			systemMailbox: mpsc.New(),
    34  			userMailbox:   q,
    35  			middlewares:   mailboxStats,
    36  		}
    37  	}
    38  }