diff options
| author | demo <demo@antix1> | 2026-05-31 00:08:43 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-31 00:09:19 -0400 |
| commit | 60cc56edc55290cd0999bd859a1dfa2c8dbc96d5 (patch) | |
| tree | 13a2295d26b8ac74e00b264c73586ffc6342e78c | |
| parent | 94093807a03d295f82bcec82244f68fb10efe312 (diff) | |
feat: use for-select instead of range
| -rw-r--r-- | workers.go | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -33,23 +33,23 @@ func workers(startURL url.URL, maxConcurrency, maxURLs, maxDepth int) { // the urls channel (unseen links.) for i := range maxConcurrency { wg.Go(func() { - for p := range packets { - batch := getBatch(p.url) - - // Convert URLs to Packets. In the - // process, bump up the depth by 1. - ps := convertToPackets(batch, p.depth+1) - + for { select { case <-ctx.Done(): fmt.Printf("exiting early %d\n", i+1) - return - default: + case p, ok := <-packets: + if !ok { + fmt.Printf("exiting because packets is closed %d\n", i+1) + } + + batch := getBatch(p.url) + + // Convert URLs to Packets. In the + // process, bump up the depth by 1. + ps := convertToPackets(batch, p.depth+1) go func() { worklist <- ps }() } } - - fmt.Printf("terminating %d\n", i+1) }) } |
