diff options
author | Alexander Kiryukhin <a.kiryukhin@corp.mail.ru> | 2019-04-04 11:54:24 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@corp.mail.ru> | 2019-04-04 11:54:24 +0300 |
commit | 08cbc9b6c05427fd3864bab55a4b40146c54639d (patch) | |
tree | c44ab6f2b976a974c20894b29ee0401b5c073676 /mixins.go | |
parent | c86dd5f3d70d310a26da73ee4ef2897121c18909 (diff) |
Changed:
- Refactored errors chan
Fixed:
- Small fixes
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) } |