bubbletea icon indicating copy to clipboard operation
bubbletea copied to clipboard

Improve godoc on `tea.Program.Start()`

Open NiloCK opened this issue 2 years ago • 0 comments

https://github.com/charmbracelet/bubbletea/blob/14e58aa1f92fa9bd756d9e739ce63a39e98a39ac/tea.go#L584

This is an important function, which will be called by every beginner user in every program.

  • "Ignores the final model." is not a complete sentence, and I don't understand it anyhow.
  • There is no indication that Start is blocking. I scratched my head quite a bit before replacing this:
if err := game.Start(); err != nil {
	fmt.Printf("error starting server game: %v", err)
	os.Exit(1)
}

// why isn't my connection receiving game updates and forwarding them?
for {
	bf := make([]byte, 5120)
		n, err := conn.Read(bf)
	if err != nil {
		panic(err)
	}

	var gs c4.GameState
	json.Unmarshal(bf[:n], &gs)
	game.Send(gs)
}

with this:

go func() {
	for {
		bf := make([]byte, 5120)

		n, err := conn.Read(bf)
		if err != nil {
			panic(err)
		}
		var gs c4.GameState
		json.Unmarshal(bf[:n], &gs)

		game.Send(gs)
	}
}()

if err := game.Start(); err != nil {
	fmt.Printf("error starting server game: %v", err)
	os.Exit(1)
}

See the godoc on exec.Run and exec.Start for examples of well communicated blocking / nonblocking.

NiloCK avatar Apr 15 '22 03:04 NiloCK