File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ type Ramcache struct {
3131 frozen bool
3232 done chan bool
3333 sync.RWMutex
34+ shutdownOnce sync.Once
3435}
3536
3637// New creates a Ramcache with a TTL of 5 minutes. You can change
@@ -156,7 +157,7 @@ func (rc *Ramcache) Keys() []string {
156157// Shutdown cleanly stops any background work, allowing Ramcache
157158// to be garbage collected.
158159func (rc * Ramcache ) Shutdown () {
159- close (rc .done )
160+ rc . shutdownOnce . Do ( func () { close (rc .done ) } )
160161}
161162
162163func (rc * Ramcache ) cleanup () {
Original file line number Diff line number Diff line change @@ -263,6 +263,17 @@ func TestBool(t *testing.T) {
263263 }
264264}
265265
266+ func TestShutdownMultiple (t * testing.T ) {
267+ r := New ()
268+ r .Set ("asdfqwer" , true )
269+ r .Set ("zxcvzxcv" , false )
270+ r .Shutdown ()
271+ r .Shutdown ()
272+ r .Shutdown ()
273+ r .Shutdown ()
274+ r .Shutdown ()
275+ }
276+
266277func BenchmarkSet (b * testing.B ) {
267278 r := New ()
268279 for i := 0 ; i < b .N ; i ++ {
You can’t perform that action at this time.
0 commit comments