Add queue to prevent writing too many files at once.

This commit is contained in:
Mark Beamer Jr 2021-05-20 20:43:01 -04:00
parent c1caf1938c
commit 76ece1e117
No known key found for this signature in database
GPG key ID: 1C314FB89AD76973

View file

@ -23,11 +23,13 @@ func init() {
writeCh = make(chan writeRequest) writeCh = make(chan writeRequest)
for i := 0; i < runtime.NumCPU(); i++ { for i := 0; i < runtime.NumCPU(); i++ {
go func() { go func() {
select { for {
case r := <-writeCh: select {
err := ioutil.WriteFile(r.filename, r.data, r.perm) case r := <-writeCh:
if err != nil { err := ioutil.WriteFile(r.filename, r.data, r.perm)
log.Errorf("could not write file %s to disk, failed with error: %s", r.filename, err.Error()) if err != nil {
log.Errorf("could not write file %s to disk, failed with error: %s", r.filename, err.Error())
}
} }
} }
}() }()