summaryrefslogtreecommitdiff
path: root/chan.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-18 01:34:32 -0600
committerJeff Carr <[email protected]>2024-01-18 01:34:32 -0600
commitf3d6daa29eccbaeb7b9b1709b4ddffe010c00bd0 (patch)
tree038e8e6183c95333f90153129d2c17cbdf099125 /chan.go
parent939e87c2e960424fdb00849273fb1e1c2d871aad (diff)
fix paths
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'chan.go')
-rw-r--r--chan.go110
1 files changed, 55 insertions, 55 deletions
diff --git a/chan.go b/chan.go
index 0956c48..2385760 100644
--- a/chan.go
+++ b/chan.go
@@ -7,11 +7,11 @@ package debugger
import (
// "regexp"
// "go.wit.com/gui/toolkit"
- "sync"
- "runtime"
"github.com/sourcegraph/conc"
- "github.com/sourcegraph/conc/stream"
"github.com/sourcegraph/conc/panics"
+ "github.com/sourcegraph/conc/stream"
+ "runtime"
+ "sync"
"go.wit.com/log"
)
@@ -60,65 +60,65 @@ func ExampleCatcher(f func()) {
}
func mapStream(
- in chan int,
- out chan int,
- f func(int) int,
+ in chan int,
+ out chan int,
+ f func(int) int,
) {
- tasks := make(chan func())
- taskResults := make(chan chan int)
+ tasks := make(chan func())
+ taskResults := make(chan chan int)
- // Worker goroutines
- var workerWg sync.WaitGroup
- for i := 0; i < 10; i++ {
- workerWg.Add(1)
- go func() {
- defer workerWg.Done()
- for task := range tasks {
- task()
- }
- }()
- }
+ // Worker goroutines
+ var workerWg sync.WaitGroup
+ for i := 0; i < 10; i++ {
+ workerWg.Add(1)
+ go func() {
+ defer workerWg.Done()
+ for task := range tasks {
+ task()
+ }
+ }()
+ }
- // Ordered reader goroutines
- var readerWg sync.WaitGroup
- readerWg.Add(1)
- go func() {
- defer readerWg.Done()
- for result := range taskResults {
- item := <-result
- out <- item
- }
- }()
+ // Ordered reader goroutines
+ var readerWg sync.WaitGroup
+ readerWg.Add(1)
+ go func() {
+ defer readerWg.Done()
+ for result := range taskResults {
+ item := <-result
+ out <- item
+ }
+ }()
- // Feed the workers with tasks
- for elem := range in {
- resultCh := make(chan int, 1)
- taskResults <- resultCh
- tasks <- func() {
- resultCh <- f(elem)
- }
- }
+ // Feed the workers with tasks
+ for elem := range in {
+ resultCh := make(chan int, 1)
+ taskResults <- resultCh
+ tasks <- func() {
+ resultCh <- f(elem)
+ }
+ }
- // We've exhausted input.
- // Wait for everything to finish
- close(tasks)
- workerWg.Wait()
- close(taskResults)
- readerWg.Wait()
+ // We've exhausted input.
+ // Wait for everything to finish
+ close(tasks)
+ workerWg.Wait()
+ close(taskResults)
+ readerWg.Wait()
}
func mapStream2(
- in chan int,
- out chan int,
- f func(int) int,
+ in chan int,
+ out chan int,
+ f func(int) int,
) {
- s := stream.New().WithMaxGoroutines(10)
- for elem := range in {
- elem := elem
- s.Go(func() stream.Callback {
- res := f(elem)
- return func() { out <- res }
- })
- }
- s.Wait()
+ s := stream.New().WithMaxGoroutines(10)
+ for elem := range in {
+ elem := elem
+ s.Go(func() stream.Callback {
+ res := f(elem)
+ return func() { out <- res }
+ })
+ }
+ s.Wait()
}