aboutsummaryrefslogtreecommitdiff
path: root/options.go
diff options
context:
space:
mode:
Diffstat (limited to 'options.go')
-rw-r--r--[-rwxr-xr-x]options.go57
1 files changed, 9 insertions, 48 deletions
diff --git a/options.go b/options.go
index 8144dde..d1030ba 100755..100644
--- a/options.go
+++ b/options.go
@@ -1,51 +1,12 @@
package rutina
-import (
- "context"
- "log"
- "os"
+type Options int
+
+const (
+ ShutdownIfFail Options = iota // Shutdown all routines if fail
+ RestartIfFail // Restart this routine if fail
+ DoNothingIfFail // Do nothing on fail
+ ShutdownIfDone // Shutdown all routines if this routine done without errors
+ RestartIfDone // Restart if this routine done without errors
+ DoNothingIfDone // Do nothing if this routine done without errors
)
-
-type Option interface {
- apply(*Rutina)
-}
-
-type OptionContext struct {
- Context context.Context
-}
-
-func WithContext(context context.Context) *OptionContext {
- return &OptionContext{Context: context}
-}
-
-func (o OptionContext) apply(r *Rutina) {
- ctx, cancel := context.WithCancel(o.Context)
- r.ctx = ctx
- r.Cancel = cancel
-}
-
-type OptionLogger struct {
- Logger *log.Logger
-}
-
-func WithLogger(logger *log.Logger) *OptionLogger {
- return &OptionLogger{Logger: logger}
-}
-
-func WithStdLogger() *OptionLogger {
- return &OptionLogger{Logger: log.New(os.Stdout, "rutina", log.LstdFlags)}
-}
-
-func (o OptionLogger) apply(r *Rutina) {
- r.logger = o.Logger
-}
-
-type OptionCancelByError struct{}
-
-func WithCancelByError() *OptionCancelByError {
- return &OptionCancelByError{}
-}
-
-func (OptionCancelByError) apply(r *Rutina) {
- r.cancelByError = true
-}