fix poll/send race condition and panic on errors instead of ignoring
This commit is contained in:
parent
221cbab51a
commit
f5ebd3b5f1
3 changed files with 37 additions and 8 deletions
24
event.go
24
event.go
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue