Fix some more races

This commit is contained in:
2023-03-10 00:07:29 +10:30
parent f2c05d0144
commit 3e7a3a2f3b
2 changed files with 21 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package download
import (
"encoding/json"
"fmt"
"io"
"log"
@@ -61,6 +62,18 @@ func (m *Manager) ManageQueue() {
}
}
func (m *Manager) DownloadsAsJSON() ([]byte, error) {
m.Lock.Lock()
defer m.Lock.Unlock()
for _, dl := range m.Downloads {
dl.Lock.Lock()
defer dl.Lock.Unlock()
}
b, err := json.Marshal(m.Downloads)
return b, err
}
// startQueued starts any downloads that have been queued, we would not exceed
// maxRunning. If maxRunning is 0, there is no limit.
func (m *Manager) startQueued(maxRunning int) {