@@ -7,15 +7,9 @@ import (
77 "sync/atomic"
88)
99
10- var (
11- // ErrMailboxNotStarted is an error returned by Mailbox.Send when sending is performed
12- // on a mailbox that has not been started.
13- ErrMailboxNotStarted = errors .New ("Mailbox is not started" )
14-
15- // ErrMailboxStopped is an error returned by Mailbox.Send when sending is performed
16- // on a mailbox that has been stopped.
17- ErrMailboxStopped = errors .New ("Mailbox is stopped" )
18- )
10+ // ErrMailboxStopped is an error returned by Mailbox.Send when sending is performed
11+ // on a mailbox that has been stopped.
12+ var ErrMailboxStopped = errors .New ("Mailbox is stopped" )
1913
2014// Mailbox is interface for message transport mechanism between Actors.
2115type Mailbox [T any ] interface {
@@ -105,9 +99,8 @@ func NewMailboxes[T any](count int, opt ...MailboxOption) []Mailbox[T] {
10599// behave like unbuffered channel.
106100//
107101// The Mailbox can send messages only after it has been started.
108- // Attempting to send a message before starting will result in an error
109- // ErrMailboxNotStarted. If a message is sent after the mailbox has been stopped,
110- // ErrMailboxStopped will be returned.
102+ // Attempting to send a message before starting can block the caller. If a message is sent
103+ // after the mailbox has been stopped,ErrMailboxStopped will be returned.
111104//
112105// A Mailbox can be started and stopped only once. Restarting a stopped mailbox
113106// has no effect.
@@ -169,9 +162,7 @@ func (m *mailboxChan[T]) Stop() {
169162
170163func (m * mailboxChan [T ]) Send (ctx Context , msg T ) error {
171164 state := m .state .Load ()
172- if state == mbxStateNotStarted {
173- return fmt .Errorf ("Mailbox.Send failed: %w" , ErrMailboxNotStarted )
174- } else if state == mbxStateStopped {
165+ if state == mbxStateStopped {
175166 return fmt .Errorf ("Mailbox.Send failed: %w" , ErrMailboxStopped )
176167 }
177168
@@ -237,9 +228,7 @@ func (m *mailbox[T]) Stop() {
237228
238229func (m * mailbox [T ]) Send (ctx Context , msg T ) error {
239230 state := m .state .Load ()
240- if state == mbxStateNotStarted {
241- return fmt .Errorf ("Mailbox.Send failed: %w" , ErrMailboxNotStarted )
242- } else if state == mbxStateStopped {
231+ if state == mbxStateStopped {
243232 return fmt .Errorf ("Mailbox.Send failed: %w" , ErrMailboxStopped )
244233 }
245234
0 commit comments