diff options
Diffstat (limited to 'mixins.go')
-rwxr-xr-x | mixins.go | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -6,14 +6,17 @@ import ( "os" ) +// Mixin interface type Mixin interface { apply(*Rutina) } +// MixinContext propagates user defined context to rutina type MixinContext struct { Context context.Context } +// WithContext propagates user defined context to rutina func WithContext(context context.Context) *MixinContext { return &MixinContext{Context: context} } @@ -24,14 +27,17 @@ func (o MixinContext) apply(r *Rutina) { r.Cancel = cancel } +// MixinLogger adds logger to rutina type MixinLogger struct { Logger *log.Logger } +// WithLogger adds custom logger to rutina func WithLogger(logger *log.Logger) *MixinLogger { return &MixinLogger{Logger: logger} } +// WithStdLogger adds standard logger to rutina func WithStdLogger() *MixinLogger { return &MixinLogger{Logger: log.New(os.Stdout, "rutina", log.LstdFlags)} } @@ -40,14 +46,15 @@ func (o MixinLogger) apply(r *Rutina) { r.logger = o.Logger } +// MixinErrChan turns on errors channel on rutina type MixinErrChan struct { - errCh chan error } -func WithErrChan(errCh chan error) *MixinErrChan { - return &MixinErrChan{errCh: errCh} +// WithErrChan turns on errors channel on rutina +func WithErrChan() *MixinErrChan { + return &MixinErrChan{} } func (o MixinErrChan) apply(r *Rutina) { - r.errCh = o.errCh + r.errCh = make(chan error, 1) } |