From cc0357f5252666ef67bb8f73f86b47ddbdb245be Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 5 Nov 2019 11:49:42 +1100 Subject: Optimize AtomicSet --- var.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'var.go') diff --git a/var.go b/var.go index 4859643..facad56 100644 --- a/var.go +++ b/var.go @@ -19,6 +19,17 @@ func (v *Var) loadState() varSnapshot { func (v *Var) changeValue(new interface{}) { version := v.loadState().version v.state.Store(varSnapshot{version: version + 1, val: new}) + v.wakeWatchers() +} + +func (v *Var) wakeWatchers() { + v.watchers.Range(func(k, _ interface{}) bool { + tx := k.(*Tx) + tx.mu.Lock() + tx.cond.Broadcast() + tx.mu.Unlock() + return true + }) } type varSnapshot struct { -- cgit v1.2.3