aboutsummaryrefslogtreecommitdiff
path: root/fs.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2021-02-06 10:22:14 +0100
committerGravatar GitHub <noreply@github.com> 2021-02-06 10:22:14 +0100
commit3cec26d42db0529f14e82115515c9731ead2dd78 (patch)
treedcac50a16051b55efa1450fbd251979d27aa7424 /fs.go
parentFix race condition in Client.DoTimeout (diff)
downloadfasthttp-3cec26d42db0529f14e82115515c9731ead2dd78.tar.gz
fasthttp-3cec26d42db0529f14e82115515c9731ead2dd78.tar.bz2
fasthttp-3cec26d42db0529f14e82115515c9731ead2dd78.zip
Allow stopping FS handler cleanup gorountine (#942)
* Allow stopping FS handler cleanup gorountine * CleanStop
Diffstat (limited to 'fs.go')
-rw-r--r--fs.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/fs.go b/fs.go
index 77a2a24..f8d4add 100644
--- a/fs.go
+++ b/fs.go
@@ -282,6 +282,11 @@ type FS struct {
// FSCompressedFileSuffixes is used by default.
CompressedFileSuffixes map[string]string
+ // If CleanStop is set, the channel can be closed to stop the cleanup handlers
+ // for the FS RequestHandlers created with NewRequestHandler.
+ // NEVER close this channel while the handler is still being used!
+ CleanStop chan struct{}
+
once sync.Once
h RequestHandler
}
@@ -399,9 +404,29 @@ func (fs *FS) initRequestHandler() {
go func() {
var pendingFiles []*fsFile
+
+ clean := func() {
+ pendingFiles = h.cleanCache(pendingFiles)
+ }
+
+ if fs.CleanStop != nil {
+ t := time.NewTicker(cacheDuration / 2)
+ for {
+ select {
+ case <-t.C:
+ clean()
+ case _, stillOpen := <-fs.CleanStop:
+ // Ignore values send on the channel, only stop when it is closed.
+ if !stillOpen {
+ t.Stop()
+ return
+ }
+ }
+ }
+ }
for {
time.Sleep(cacheDuration / 2)
- pendingFiles = h.cleanCache(pendingFiles)
+ clean()
}
}()