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

     1  package actor
     2  
     3  import (
     4  	"sync/atomic"
     5  )
     6  
     7  type ActorProcess struct {
     8  	mailbox Mailbox
     9  	dead    int32
    10  }
    11  
    12  var _ Process = &ActorProcess{}
    13  
    14  func NewActorProcess(mailbox Mailbox) *ActorProcess {
    15  	return &ActorProcess{
    16  		mailbox: mailbox,
    17  	}
    18  }
    19  
    20  func (ref *ActorProcess) SendUserMessage(_ *PID, message interface{}) {
    21  	ref.mailbox.PostUserMessage(message)
    22  }
    23  
    24  func (ref *ActorProcess) SendSystemMessage(_ *PID, message interface{}) {
    25  	ref.mailbox.PostSystemMessage(message)
    26  }
    27  
    28  func (ref *ActorProcess) Stop(pid *PID) {
    29  	atomic.StoreInt32(&ref.dead, 1)
    30  	ref.SendSystemMessage(pid, stopMessage)
    31  }