Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add method for blocking until shutdown is complete #726

Closed
wants to merge 1 commit into from

Conversation

meowgorithm
Copy link
Member

@meowgorithm meowgorithm commented Apr 18, 2023

This feature introduces a Program.Done() method which will block until a Program has completely exited. This is useful when you want to wait until Bubble Tea has completely restored the terminal before printing output elsewhere in your Go application.

In particular, this feature can help prevent race conditions where Bubble Tea and other output are attempting to print to the terminal at the same time.

Consider the following:

// Draw a spinner
go func() {
	if _, err := p.Run(); err != nil {
		fmt.Println("Uh oh:", err)
		return
	}
}()

result := someLongRunningOperation()

p.Quit()   // stop the spinner
<-p.Done() // wait for cleanup

// Print safely.
fmt.Println("Okay, so the results are in:", result)

It may also make sense to include a convenience function which combines Program.Quit and Program.Done. Potentially named Program.Shutdown()?

@meowgorithm
Copy link
Member Author

Closing in favor of #722, which has a much nicer API!

@meowgorithm meowgorithm deleted the donechan branch April 19, 2023 16:50
@meowgorithm meowgorithm mentioned this pull request Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant