mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
fix: don't block in Send after shutdown
Send should block before a tea.Program has been started, but result in a no-op when it has already been terminated. Fixed godocs.
This commit is contained in:
26
tea_test.go
26
tea_test.go
@@ -149,3 +149,29 @@ func TestTeaSequenceMsg(t *testing.T) {
|
||||
t.Fatalf("counter should be 2, got %d", m.counter.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTeaSend(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
var in bytes.Buffer
|
||||
|
||||
m := &testModel{}
|
||||
p := NewProgram(m, WithInput(&in), WithOutput(&buf))
|
||||
|
||||
// sending before the program is started is a blocking operation
|
||||
go p.Send(Quit())
|
||||
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// sending a message after program has quit is a no-op
|
||||
p.Send(Quit())
|
||||
}
|
||||
|
||||
func TestTeaNoRun(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
var in bytes.Buffer
|
||||
|
||||
m := &testModel{}
|
||||
NewProgram(m, WithInput(&in), WithOutput(&buf))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user