Documentation
¶
Overview ¶
Package task is the generation-tracked async work manager for a Bubble Tea app: named scopes group work, every start bumps the scope's monotonic generation, and a finished result is accepted only while its generation is still the latest — so a superseded fetch (the user refreshed again, changed filters, moved on) is dropped instead of overwriting newer state. All bookkeeping happens on the single Update goroutine, so there is no locking; the run closure executes off-loop in the returned command and never touches the manager. There is deliberately no "task started" message: the caller sets its own loading state synchronously when it starts work, which avoids any ordering race against the finished message for fast tasks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FinishedMsg ¶
FinishedMsg carries the result of a task. The app drops it unless its generation is still the latest for the scope (see Manager.Accept), then routes it to whichever component owns the scope — even if the user has since switched to a different view.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager hands out monotonic generations per scope so stale results can be discarded. All of its methods are called from the single Bubble Tea update goroutine, so the generation map needs no locking: Start runs during Update, Accept runs during Update, and the async Run closure never touches it.
func (*Manager) Accept ¶
Accept reports whether a finished task is still the latest for its scope. A false result means the user moved on and the work should be discarded.
func (*Manager) Generation ¶
Generation returns the current generation for a scope (0 if never started).
func (*Manager) Start ¶
Start bumps the scope's generation and returns a command that runs Run off the UI loop and reports the outcome as a FinishedMsg tagged with the captured generation. A later Start in the same scope makes this task's eventual result stale. The map is lazily initialized so a zero-value manager is usable.
type Scope ¶
type Scope string
Scope groups async work so that a newer task in the same scope supersedes an older one. For example all issue fetches share one scope; if the user refreshes twice quickly, only the latest result is accepted.