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

Expose atomic update to current stage #2

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions stage.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
package progress

import "sync/atomic"

type Stager interface {
Stage() string
}

type Stage struct {
Current string
currentStage atomic.Value
}

func (s *Stage) getCurrentStage() string {
return s.currentStage.Load().(string)
}

func (s *Stage) setCurrentStage(newStage string) {
s.currentStage.Store(newStage)
}

func (s *Stage) Stage() string {
return s.getCurrentStage()
}

func (s *Stage) Set(newStage string) {
s.setCurrentStage(newStage)
}

func (s Stage) Stage() string {
return s.Current
func NewStage(current string) *Stage {
result := Stage{}
result.currentStage.Store(current)
return &result
}

type StagerSettable interface {
Stager
Set(newStage string)
}

type StagedMonitorable interface {
Expand Down