From 08cbc9b6c05427fd3864bab55a4b40146c54639d Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Thu, 4 Apr 2019 11:54:24 +0300 Subject: Changed: - Refactored errors chan Fixed: - Small fixes --- mixins.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'mixins.go') diff --git a/mixins.go b/mixins.go index a037561..1cc2c76 100755 --- a/mixins.go +++ b/mixins.go @@ -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) } -- cgit v1.2.3