diff options
| author | demo <demo@antix1> | 2026-05-26 18:19:34 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-26 18:19:34 -0400 |
| commit | 5cc1fc597f13c2f7c781f45b5f37169958752b04 (patch) | |
| tree | 42dcc2587a2841287e132111bd9dde1600280f5d | |
| parent | 35e2864220e493f8aa77b5808b0a26674f4f3403 (diff) | |
feat: implement maxConcurrency using a buffered channel 'sema'
| -rw-r--r-- | classic.go | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -23,6 +23,7 @@ func classic(startURL url.URL, maxConcurrency, maxURLs int) { ctx, cancel := context.WithCancel(context.Background()) var wg sync.WaitGroup + sema := make(chan struct{}, maxConcurrency) loop: for ; numPendingSends > 0; numPendingSends-- { @@ -42,7 +43,9 @@ loop: select { case <-ctx.Done(): return - case worklist <- getBatch(u): + case sema <- struct{}{}: + defer func() { <-sema }() + worklist <- getBatch(u) } }) } |
