Skip to content
Myr

Simplify send-msg example

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent 7c939e8 · Browse files · 1 file+7 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−11 removed

  • other:+7 added−11 removed

1 file+7 added−11 removed

modified:examples/send-msg/main.go+7 added-11 removed
101 unmodified lines
102103func main() {104 rand.Seed(time.Now().UTC().UnixNano())105106 done := make(chan struct{})107106 p := tea.NewProgram(newModel())109 go func() {110 if err := p.Start(); err != nil {111 fmt.Println("Error running program:", err)112 os.Exit(1)113 }114 close(done)115 }()107108 // Simulate activity109 go func() {110 for {111 pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond112 time.Sleep(pause)113123 // Send the Bubble Tea program a message from outside the program.114 // Send the Bubble Tea program a message from outside the115 // tea.Program. This will block until it is ready to receive116 // messages.117 p.Send(resultMsg{food: randomFood(), duration: pause})118 }119 }()120128 <-done121 if err := p.Start(); err != nil {122 fmt.Println("Error running program:", err)123 os.Exit(1)124 }125}126127func randomFood() string {128 food := []string{"an apple", "a pear", "a gherkin", "a party gherkin",
4 unmodified lines