diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-06-29 01:19:21 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-06-29 01:19:21 +0300 |
commit | 01eeeaf5e136928abe75f95d58f3f9cce11c6fe6 (patch) | |
tree | 700f9a5106a51ce1f8b35475c84a7bafac162313 /mixins.go | |
parent | 741cf397a9150a8f76b8f74289b1dde8aaa43d02 (diff) |
Release.v1.0.0
Auto listen OS signal (with mixin)
Policies: ...Fail -> ...Error
Diffstat (limited to 'mixins.go')
-rwxr-xr-x | mixins.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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} +} |