more async improvements and crypto bugfix

This commit is contained in:
ston1th 2022-08-17 23:58:46 +02:00
commit 304135be2e
7 changed files with 161 additions and 79 deletions

View file

@ -19,8 +19,8 @@ import (
type FS struct {
log logr.Logger
done chan struct{}
cancel func()
pCancel func()
NoCache http.Handler
src provider.FS
dst provider.FS
@ -61,11 +61,12 @@ func NewFS(quota int64, max int, src, srckey, dst, dstkey, metadata string, bloc
}
ctx, cancel := context.WithCancel(context.Background())
pCtx, pCancel := context.WithCancel(context.Background())
fs = &FS{
log: log,
done: make(chan struct{}),
cancel: cancel,
pCancel: pCancel,
NoCache: http.FileServer(http.Dir(src)),
src: srcfs,
dst: dstfs,
@ -80,7 +81,7 @@ func NewFS(quota int64, max int, src, srckey, dst, dstkey, metadata string, bloc
if err != nil {
return nil, fmt.Errorf("quota: %w", err)
}
fs.ph = NewPreloadHandler(ctx, fs, max, log.WithName("preload"))
fs.ph = NewPreloadHandler(pCtx, fs, max, log.WithName("preload"))
fs.sc = NewStatCache(ctx)
return
}
@ -265,8 +266,14 @@ func (fs *FS) CacheStatus(name string) int {
}
func (fs *FS) Close() {
fs.pCancel()
<-fs.ph.Done()
fs.cancel()
fs.src.Close()
fs.dst.Close()
<-fs.done
}
func (fs *FS) Done() <-chan struct{} {
return fs.mh.Done()
}