diff --git a/chan.go b/chan.go deleted file mode 100644 index 0fea803..0000000 --- a/chan.go +++ /dev/null @@ -1,125 +0,0 @@ -package debugger - -// channel communication to the plugins -// https://github.com/sourcegraph/conc -// https://www.reddit.com/r/golang/comments/11x1oek/hello_gophers_show_me_your_concurrent_code/ - -import ( - // "regexp" - // "go.wit.com/gui/toolkit" - "runtime" - "sync" - - "github.com/sourcegraph/conc" - "github.com/sourcegraph/conc/panics" - "github.com/sourcegraph/conc/stream" - - "go.wit.com/log" -) - -// this should never exit -// TODO: clean up all this poorly named code -func makeConc() { - var wg conc.WaitGroup - defer wg.Wait() - - startTheThing(&wg) - log.Warn("panic?") - log.Sleep(2) - log.Warn("panic? after sleep(5)") -} - -func startTheThing(wg *conc.WaitGroup) { - f := func() { - log.Warn("startTheThing() == about to panic now") - panic("test conc.WaitGroup") - } - wg.Go(func() { - ExampleCatcher(f) - }) -} - -func ExampleCatcher(f func()) { - var pc panics.Catcher - i := 0 - pc.Try(func() { i += 1 }) - pc.Try(f) - pc.Try(func() { i += 1 }) - - recovered := pc.Recovered() - - log.Warn("panic.Recovered():", recovered.Value.(string)) - frames := runtime.CallersFrames(recovered.Callers) - for { - frame, more := frames.Next() - log.Warn("\t", frame.Function) - - if !more { - break - } - } -} - -func mapStream( - in chan int, - out chan int, - f func(int) 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() - } - }() - } - - // 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) - } - } - - // 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, -) { - 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() -} diff --git a/go.mod b/go.mod index b19edab..3831f1e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module go.wit.com/lib/debugger go 1.21.4 require ( - github.com/sourcegraph/conc v0.3.0 go.wit.com/dev/alexflint/arg v1.4.5 go.wit.com/gui v0.12.19 go.wit.com/lib/gadgets v0.12.14 @@ -13,8 +12,6 @@ require ( ) require ( - go.uber.org/atomic v1.7.0 // indirect - go.uber.org/multierr v1.9.0 // indirect go.wit.com/dev/alexflint/scalar v1.2.1 // indirect go.wit.com/dev/davecgh/spew v1.1.4 // indirect ) diff --git a/go.sum b/go.sum index 3d14bad..5a32749 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,3 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= -github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= -go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.wit.com/dev/alexflint/arg v1.4.5 h1:asDx5f9IlfpknKjPBqqb2qndE91Pbo7ZDkWUgddfMhY= go.wit.com/dev/alexflint/arg v1.4.5/go.mod h1:wnWc+c6z8kSdDKYriMf6RpM+FiXmo5RYp/t4FNi0MU0= go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26TvKNs= @@ -29,5 +14,3 @@ go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4= go.wit.com/log v0.5.6/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY= go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=