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

progress: always perform a final render before exiting the render loop #173

Merged
merged 1 commit into from
Jul 11, 2021

Conversation

virtuald
Copy link
Contributor

I expect that when I call Stop() that whatever the current state of any trackers will have been written to the output. However, there's currently no guarantee that the current output was written, even if Stop is called after all of my tracker updates on the same goroutine. Here's a silly example that demonstrates the point:

package main

import (
	"time"

	"github.com/jedib0t/go-pretty/v6/progress"
)

func main() {

	var prog progress.Progress
	prog.Style().Colors = progress.StyleColorsExample
	prog.Style().Options.PercentFormat = "%4.1f%%"
	go prog.Render()

	t := progress.Tracker{
		Message: "Interesting thing",
		Total:   30,
	}

	prog.AppendTracker(&t)

	for i := 0; i < 30; i++ {
		t.Increment(1)
		time.Sleep(1 * time.Millisecond)
	}

	t.MarkAsDone()

	prog.Stop()
	for {
		if !prog.IsRenderInProgress() {
			break
		}
		time.Sleep(50 * time.Millisecond)
	}

}

If you run this without this PR applied, there will never be output shown because the render never gets a chance to run.

@sonarcloud
Copy link

sonarcloud bot commented Jul 11, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1019349029

  • 3 of 5 (60.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.07%) to 99.932%

Changes Missing Coverage Covered Lines Changed/Added Lines %
progress/render.go 3 5 60.0%
Totals Coverage Status
Change from base Build 1009327820: -0.07%
Covered Lines: 2945
Relevant Lines: 2947

💛 - Coveralls

@jedib0t jedib0t merged commit 953cf4f into jedib0t:main Jul 11, 2021
@virtuald virtuald deleted the finish-render branch July 11, 2021 05:31
@jedib0t
Copy link
Owner

jedib0t commented Jul 11, 2021

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

3 participants