Skip to content

Commit

Permalink
Merge pull request #4 from runreveal/patch-from-runreveal
Browse files Browse the repository at this point in the history
RunFunc to Runner
  • Loading branch information
abraithwaite authored Nov 25, 2023
2 parents f2e2156 + 0c0600f commit a6e4f53
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ import (
"golang.org/x/exp/slog"
)

type Runner interface {
Run(context.Context) error
}

type RunFunc func(context.Context) error

func (rf RunFunc) Run(ctx context.Context) error {
return rf(ctx)
}

type runner struct {
funcs []RunFunc
funcNames []string
Expand All @@ -37,22 +45,22 @@ func New(...Option) *runner {
}
}

func (r *runner) Add(f RunFunc) {
func (r *runner) Add(f Runner) {
r.startMu.Lock()
if r.started {
panic("Add called after Run started")
}
r.funcs = append(r.funcs, f)
r.funcs = append(r.funcs, f.Run)
r.funcNames = append(r.funcNames, "")
r.startMu.Unlock()
}

func (r *runner) AddNamed(f RunFunc, name string) {
func (r *runner) AddNamed(f Runner, name string) {
r.startMu.Lock()
if r.started {
panic("Add called after Run started")
}
r.funcs = append(r.funcs, f)
r.funcs = append(r.funcs, f.Run)
r.funcNames = append(r.funcNames, name)
r.startMu.Unlock()
}
Expand Down

0 comments on commit a6e4f53

Please sign in to comment.