Skip to content

Commit

Permalink
Simplify send-msg example
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 8, 2022
1 parent 7c939e8 commit 74f0972
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions examples/send-msg/main.go
Expand Up @@ -103,29 +103,25 @@ func (m model) View() string {
func main() {
rand.Seed(time.Now().UTC().UnixNano())

done := make(chan struct{})

p := tea.NewProgram(newModel())
go func() {
if err := p.Start(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
close(done)
}()

// Simulate activity
go func() {
for {
pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond
time.Sleep(pause)

// Send the Bubble Tea program a message from outside the program.
// Send the Bubble Tea program a message from outside the
// tea.Program. This will block until it is ready to receive
// messages.
p.Send(resultMsg{food: randomFood(), duration: pause})
}
}()

<-done
if err := p.Start(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
}

func randomFood() string {
Expand Down

0 comments on commit 74f0972

Please sign in to comment.