aboutsummaryrefslogtreecommitdiff
path: root/mixins.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@corp.mail.ru>2019-04-04 11:54:24 +0300
committerAlexander Kiryukhin <a.kiryukhin@corp.mail.ru>2019-04-04 11:54:24 +0300
commit08cbc9b6c05427fd3864bab55a4b40146c54639d (patch)
treec44ab6f2b976a974c20894b29ee0401b5c073676 /mixins.go
parentc86dd5f3d70d310a26da73ee4ef2897121c18909 (diff)
Changed:
- Refactored errors chan Fixed: - Small fixes
Diffstat (limited to 'mixins.go')
-rwxr-xr-xmixins.go15
1 files changed, 11 insertions, 4 deletions
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)
}