package main import ( "errors" "os" "os/signal" "time" ) type Runner struct { interrupt chan os.Signal complete chan error timeout <-chan time.Time tasks []func(int) } var ErrTimeout = errors.New("Received Timeout") var ErrInterrupt = errors.New("Received Interrupt") func New(d time.Duration) *Runner { return &Runner{ interrupt: make(chan os.Signal, 1), complete: make(chan error), timeout: time.After(d), } } func (r *Runner) Add(tasks ...func(int)) { r.tasks = append(r.tasks, tasks...) } func (r *Runner) Start() error { signal.Notify(r.interrupt, os.Interrupt) }