aboutsummaryrefslogtreecommitdiff
path: root/mixins.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2019-06-29 01:19:21 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2019-06-29 01:19:21 +0300
commit01eeeaf5e136928abe75f95d58f3f9cce11c6fe6 (patch)
tree700f9a5106a51ce1f8b35475c84a7bafac162313 /mixins.go
parent741cf397a9150a8f76b8f74289b1dde8aaa43d02 (diff)
Release.v1.0.0
Auto listen OS signal (with mixin) Policies: ...Fail -> ...Error
Diffstat (limited to 'mixins.go')
-rwxr-xr-xmixins.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/mixins.go b/mixins.go
index 1344d07..aea08ef 100755
--- a/mixins.go
+++ b/mixins.go
@@ -4,6 +4,7 @@ import (
"context"
"log"
"os"
+ "syscall"
)
// Mixin interface
@@ -72,3 +73,18 @@ func (l LifecycleMixin) apply(r *Rutina) {
func WithLifecycleListener(listener LifecycleListener) *LifecycleMixin {
return &LifecycleMixin{Listener: listener}
}
+
+type ListenOsSignalsMixin struct {
+ Signals []os.Signal
+}
+
+func (l ListenOsSignalsMixin) apply(r *Rutina) {
+ r.autoListenSignals = l.Signals
+}
+
+func WithListenOsSignals(signals ...os.Signal) *ListenOsSignalsMixin {
+ if len(signals) == 0 {
+ signals = []os.Signal{syscall.SIGINT, syscall.SIGTERM}
+ }
+ return &ListenOsSignalsMixin{Signals: signals}
+}