Repository navigation
Replies: 1 comment
|
There are two concrete problems in the sample. First, Second, the worker goroutines call For a bar that directly represents completed work, use func (i DownloadListItem) Description() string {
ratio := 0.0
if i.Total > 0 {
ratio = float64(i.Current) / float64(i.Total)
}
return i.Progress.ViewAs(ratio)
}Send the integer count rather than converting it to a ratio and then back to an integer: type progressMsg struct {
itemName string
current int
}
func (m *Model) UpdateProgress(name string, current int) {
m.program.Send(progressMsg{itemName: name, current: current})
}Replace the case progressMsg:
item, exists := m.Items[msg.itemName]
if !exists {
return m, nil
}
item.Current = msg.current
m.updateDownloadList()With this approach, remove the For this fixed set of downloads, initialize all items in for i := 1; i <= 3; i++ {
m.AddDownloadItem(fmt.Sprintf("Download Task %d", i), 10)
}Remove I tested these changes with Bubbles v1.0.0 / Bubble Tea v1.3.10 using three concurrent workers under |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm working on a concurrent download manager using Bubble Tea and running into a weird progress bar synchronization issue. The bars complete at different percentages depending on how fast my workers finish, which suggests I'm missing something fundamental about progress reporting.
The Symptom:
When I adjust the
time.Sleepduration in my progress updater:Sleep(10ms)→Sleep(50ms)→Sleep(200ms)→What I've Verified:
✔ All worker goroutines complete their tasks
✔ Progress messages make it to Bubble Tea
✔ The math in my percentage calculation looks correct
Core Question:
How should I properly synchronize:
I suspect this is either:
a) A timing issue between my workers and the TUI, or
b) That I'm using SetPercent incorrectly for concurrent scenarios
Has anyone implemented something similar? Would especially appreciate:
Here's a minimal example demonstrating the problem:
Code
Thanks in advance for any insights! This has me stumped after several hours of tweaking.
All reactions