diff --git a/wasm/follow.go b/wasm/follow.go index 4b343314206a28f5139b9d464fd4e965c11ea8a0..3794bb2d4c19c685b2634664466e235cf149507c 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -11,6 +11,7 @@ package wasm import ( "gitlab.com/elixxir/xxdk-wasm/utils" + "sync/atomic" "syscall/js" ) @@ -60,6 +61,8 @@ func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} { return nil } + atomic.AddUint64(&NumClientsRunning, 1) + return nil } @@ -77,6 +80,7 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { utils.Throw(utils.TypeError, err) return nil } + atomic.AddUint64(&NumClientsRunning, ^uint64(0)) return nil } diff --git a/wasm/purge.go b/wasm/purge.go new file mode 100644 index 0000000000000000000000000000000000000000..25c3664c7dde1b9991abf60df3d3db7d8a38d318 --- /dev/null +++ b/wasm/purge.go @@ -0,0 +1,15 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2022 xx foundation // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file. // +//////////////////////////////////////////////////////////////////////////////// + +package wasm + +// NumClientsRunning is an atomic that tracks the current number of Cmix +// followers that have been started. Every time one is started, this counter +// must be incremented and every time one is stopped, it must be decremented. +// +// This variable is an atomic. Only access it with atomic functions +var NumClientsRunning uint64