Reassign loop index to another variable

This commit is contained in:
Ben Adrian Sarmiento
2024-06-07 19:50:23 +02:00
parent db086b19b3
commit 1ef31ebe7b
2 changed files with 11 additions and 9 deletions

View File

@@ -123,12 +123,12 @@ func MainApp(configPath string) {
)
//// pprof
workerPool.Submit(func() {
if err := netHttp.ListenAndServe(":6060", nil); err != nil && err != netHttp.ErrServerClosed {
zurglog.Errorf("Failed to start pprof: %v", err)
os.Exit(1)
}
})
// workerPool.Submit(func() {
// if err := netHttp.ListenAndServe(":6060", nil); err != nil && err != netHttp.ErrServerClosed {
// zurglog.Errorf("Failed to start pprof: %v", err)
// os.Exit(1)
// }
// })
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
zurglog.Infof("Starting server on %s", addr)

View File

@@ -185,12 +185,13 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) {
for {
allResults := make(chan getTorrentsResult, maxParallelThreads) // Channel to collect results from goroutines
for i := 0; i < maxParallelThreads; i++ { // Launch GET_PARALLEL concurrent fetches
idx := i
rd.workerPool.Submit(func() {
if page > maxPages {
allResults <- getTorrentsResult{nil, nil, 0}
return
}
allResults <- rd.getPageOfTorrents(page+i, 250)
allResults <- rd.getPageOfTorrents(page+idx, 250)
})
}
// Collect results from all goroutines
@@ -382,13 +383,14 @@ func (rd *RealDebrid) GetDownloads() []Download {
allResults := make(chan []Download, maxParallelThreads) // Channel to collect results from goroutines
errChan := make(chan error, maxParallelThreads) // Channel to collect errors from goroutines
for i := 0; i < maxParallelThreads; i++ { // Launch GET_PARALLEL concurrent fetches
idx := i
rd.workerPool.Submit(func() {
if page+i > maxPages {
if page+idx > maxPages {
allResults <- nil
errChan <- nil
return
}
result, _, err := rd.fetchPageOfDownloads(page+i, limit)
result, _, err := rd.fetchPageOfDownloads(page+idx, limit)
if err != nil {
allResults <- nil
errChan <- err