From 01eeeaf5e136928abe75f95d58f3f9cce11c6fe6 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Sat, 29 Jun 2019 01:19:21 +0300 Subject: Release. Auto listen OS signal (with mixin) Policies: ...Fail -> ...Error --- mixins.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mixins.go') 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} +} -- cgit v1.2.3