From c2ccab4361ef8a8f76df6754e2de86f687b64628 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sun, 28 Jun 2015 20:09:10 +0100 Subject: [PATCH] Add unsubscribe to config --- lib/config/wrapper.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/config/wrapper.go b/lib/config/wrapper.go index 84799728e..8b054c29a 100644 --- a/lib/config/wrapper.go +++ b/lib/config/wrapper.go @@ -114,6 +114,21 @@ func (w *Wrapper) Subscribe(c Committer) { w.sMut.Unlock() } +// Unsubscribe de-registers the given handler from any future calls to +// configuration changes +func (w *Wrapper) Unsubscribe(c Committer) { + w.sMut.Lock() + for i := range w.subs { + if w.subs[i] == c { + copy(w.subs[i:], w.subs[i+1:]) + w.subs[len(w.subs)-1] = nil + w.subs = w.subs[:len(w.subs)-1] + break + } + } + w.sMut.Unlock() +} + // Raw returns the currently wrapped Configuration object. func (w *Wrapper) Raw() Configuration { return w.cfg