fix poll/send race condition and panic on errors instead of ignoring

This commit is contained in:
Lobo 2025-10-11 23:29:58 -03:00
parent 221cbab51a
commit f5ebd3b5f1
3 changed files with 37 additions and 8 deletions

View file

@ -4,25 +4,37 @@ type IncomingEvent interface {
HandleIncoming(*App)
}
type OutgoingEvent interface {
HandleOutgoing(*App)
HandleOutgoing(*App) error
}
type Message string
func (m Message) HandleIncoming(app *App) {
app.AppendMessage(string(m))
}
func (m Message) HandleOutgoing(app *App) {
num, _ := app.Send(string(m))
func (m Message) HandleOutgoing(app *App) error {
num, err := app.Send(string(m))
if err != nil {
return err
}
app.incoming <- SetLast(num)
return nil
}
type Poll int
func (p Poll) HandleOutgoing(app *App) {
num, _ := app.Poll(int(p))
go app.Last(num)
func (p Poll) HandleOutgoing(app *App) error {
num, err := app.Poll(int(p))
if err != nil {
return err
}
err = app.Last(num)
if err != nil {
return err
}
return nil
}
type SetLast int