Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7555cff

Browse files
committed
remove some references
1 parent c91c254 commit 7555cff

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

coderd/files/closer.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@ import (
1313
type CacheCloser struct {
1414
cache FileAcquirer
1515

16-
close []*CloseFS
17-
mu sync.Mutex
18-
closed bool
16+
closers []func()
17+
mu sync.Mutex
18+
closed bool
1919
}
2020

2121
func NewCacheCloser(cache FileAcquirer) *CacheCloser {
2222
return &CacheCloser{
23-
cache: cache,
24-
close: make([]*CloseFS, 0),
23+
cache: cache,
24+
closers: make([]func(), 0),
2525
}
2626
}
2727

2828
func (c *CacheCloser) Close() {
2929
c.mu.Lock()
3030
defer c.mu.Unlock()
3131

32-
for _, fs := range c.close {
33-
fs.Close()
32+
for _, doClose := range c.closers {
33+
doClose()
3434
}
3535
c.closed = true
36+
37+
// Remove any references
38+
c.closers = make([]func(), 0)
3639
}
3740

3841
func (c *CacheCloser) Acquire(ctx context.Context, fileID uuid.UUID) (*CloseFS, error) {
@@ -48,7 +51,7 @@ func (c *CacheCloser) Acquire(ctx context.Context, fileID uuid.UUID) (*CloseFS,
4851
return nil, err
4952
}
5053

51-
c.close = append(c.close, f)
54+
c.closers = append(c.closers, f.close)
5255

5356
return f, nil
5457
}

0 commit comments

Comments
 (0)