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 //// pprof
workerPool.Submit(func() { // workerPool.Submit(func() {
if err := netHttp.ListenAndServe(":6060", nil); err != nil && err != netHttp.ErrServerClosed { // if err := netHttp.ListenAndServe(":6060", nil); err != nil && err != netHttp.ErrServerClosed {
zurglog.Errorf("Failed to start pprof: %v", err) // zurglog.Errorf("Failed to start pprof: %v", err)
os.Exit(1) // os.Exit(1)
} // }
}) // })
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort()) addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
zurglog.Infof("Starting server on %s", addr) zurglog.Infof("Starting server on %s", addr)

View File

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