iter/export_test.go2
3:5exported-declaration-comment
iter/export_test.go:3:5
var DefaultMaxGoroutines = defaultMaxGoroutines3:5no-package-var
iter/export_test.go:3:5
var DefaultMaxGoroutines = defaultMaxGoroutinesiter/iter.go9
1:1format
iter/iter.go:1:1
package iter- Fix (safe): run `strider fmt iter/iter.go`
1:9package-comments
iter/iter.go:1:9
package iter19:1top-level-declaration-order
iter/iter.go:19:1
// Iterator is also safe for reuse and concurrent use.type Iterator[T any] struct { // MaxGoroutines controls the maximum number of goroutines36:6exported-declaration-comment
iter/iter.go:36:6
// a configurable goroutine limit, use a custom Iterator.func ForEach[T any](input []T, f func(*T)) { Iterator[T]{}.ForEach(input, f) }47:25exported-declaration-comment
iter/iter.go:47:25
// an overhead of roughly 50ns per element of input.func (iter Iterator[T]) ForEach(input []T, f func(*T)) { iter.ForEachIdx(input, func(_ int, t *T) {55:6exported-declaration-comment
iter/iter.go:55:6
// index of the element to the callback.func ForEachIdx[T any](input []T, f func(int, *T)) { Iterator[T]{}.ForEachIdx(input, f) }59:25exported-declaration-comment
iter/iter.go:59:25
// index of the element to the callback.func (iter Iterator[T]) ForEachIdx(input []T, f func(int, *T)) { if iter.MaxGoroutines == 0 {62:3modifies-value-receiver
iter/iter.go:62:3
// iter is a value receiver and is hence safe to mutate iter.MaxGoroutines = defaultMaxGoroutines() }68:3modifies-value-receiver
iter/iter.go:68:3
// No more concurrent tasks than the number of input items. iter.MaxGoroutines = numInput }iter/iter_test.go4
1:1format
iter/iter_test.go:1:1
package iter_test- Fix (safe): run `strider fmt iter/iter_test.go`
26:2discarded-error-result
iter/iter_test.go:26:2
fmt.Println(input) // Output:50:34nested-structs
iter/iter_test.go:50:34
maxConcurrencyHit := make(chan struct{})173:30range-value-capture
iter/iter_test.go:173:30
for _, count := range []int{0, 1, 8, 100, 1000, 10000, 100000} { b.Run(strconv.Itoa(count), func(b *testing.B) { ints := make([]int, count)iter/map.go4
1:9package-comments
iter/map.go:1:9
package iter19:6exported-declaration-comment
iter/map.go:19:6
// goroutine limit, use a custom Mapper.func Map[T, R any](input []T, f func(*T) R) []R { return Mapper[T, R]{}.Map(input, f)39:6exported-declaration-comment
iter/map.go:39:6
// goroutine limit, use a custom Mapper.func MapErr[T, R any](input []T, f func(*T) (R, error)) ([]R, error) { return Mapper[T, R]{}.MapErr(input, f)47:23exported-declaration-comment
iter/map.go:47:23
// Map uses up to the configured Mapper's maximum number of goroutines.func (m Mapper[T, R]) MapErr(input []T, f func(*T) (R, error)) ([]R, error) { var (iter/map_test.go5
1:1format
iter/map_test.go:1:1
package iter_test- Fix (safe): run `strider fmt iter/map_test.go`
20:2discarded-error-result
iter/map_test.go:20:2
results := mapper.Map(input, func(v *int) bool { return *v%2 == 0 }) fmt.Println(results) // Output:84:6function-length
iter/map_test.go:84:6
func TestMapErr(t *testing.T) { t.Parallel()104:11discarded-error-result
iter/map_test.go:104:11
ints := []int{1} _, _ = iter.MapErr(ints, func(val *int) (int, error) { panic("super bad thing happened")165:31unchecked-type-assertion
iter/map_test.go:165:31
require.ErrorIs(t, err, err2) require.ElementsMatch(t, err.(interface{ Unwrap() []error }).Unwrap(), []error{err1, err2}) require.Equal(t, []int{2, 3, 0, 0, 6}, res)panics/panics.go10
1:1format
panics/panics.go:1:1
package panics- Fix (safe): run `strider fmt panics/panics.go`
1:9package-comments
panics/panics.go:1:9
package panics15:6exported-declaration-comment
panics/panics.go:15:6
// propagate the panic (re-panic) with Repanic().type Catcher struct { recovered atomic.Pointer[Recovered]21:19exported-declaration-comment
panics/panics.go:21:19
// to call from multiple goroutines simultaneously.func (p *Catcher) Try(f func()) { defer p.tryRecover()36:19exported-declaration-comment
panics/panics.go:36:19
// information.func (p *Catcher) Repanic() { if val := p.Recovered(); val != nil {44:19exported-declaration-comment
panics/panics.go:44:19
// no calls to Try panicked.func (p *Catcher) Recovered() *Recovered { return p.recovered.Load()64:1top-level-declaration-order
panics/panics.go:64:1
// Recovered is a panic that was caught with recover().type Recovered struct { // The original value of the panic.83:21exported-declaration-comment
panics/panics.go:83:21
// is unwrappable with the cause of the panic, if the panic was provided one.func (p *Recovered) AsError() error { if p == nil {91:6error-type-naming
panics/panics.go:91:6
// ErrRecovered wraps a panics.Recovered in an error implementation.type ErrRecovered struct{ Recovered }93:5error-naming
panics/panics.go:93:5
var _ error = (*ErrRecovered)(nil)panics/panics_test.go9
1:1format
panics/panics_test.go:1:1
package panics_test- Fix (safe): run `strider fmt panics/panics_test.go`
25:2discarded-error-result
panics/panics_test.go:25:2
fmt.Println(i) fmt.Println(rc.Value.(string))26:2discarded-error-result
panics/panics_test.go:26:2
fmt.Println(i) fmt.Println(rc.Value.(string)) // Output:26:22unchecked-type-assertion
panics/panics_test.go:26:22
fmt.Println(i) fmt.Println(rc.Value.(string)) // Output:46:3discarded-error-result
panics/panics_test.go:46:3
fmt.Println(frame.Function)79:4discarded-error-result
panics/panics_test.go:79:4
if cause := errors.Unwrap(err); cause != nil { fmt.Printf("helper panicked with an error: %s", cause) }89:21error-strings
panics/panics_test.go:89:21
err1 := errors.New("SOS")105:21test-parallelism
panics/panics_test.go:105:21
t.Run("not error", func(t *testing.T) { var pc panics.Catcher113:26test-parallelism
panics/panics_test.go:113:26
t.Run("repanic panics", func(t *testing.T) { var pc panics.Catcherpanics/try.go2
1:9package-comments
panics/try.go:1:9
package panics7:6exported-declaration-comment
panics/try.go:7:6
// (*panics.Recovered).AsError().func Try(f func()) *Recovered { var c Catcherpanics/try_test.go2
1:1format
panics/try_test.go:1:1
package panics_test- Fix (safe): run `strider fmt panics/try_test.go`
18:21error-strings
panics/try_test.go:18:21
err := errors.New("SOS") recovered := panics.Try(func() { panic(err) })pool/context_pool.go11
1:1format
pool/context_pool.go:1:1
package pool- Fix (safe): run `strider fmt pool/context_pool.go`
1:9package-comments
pool/context_pool.go:1:9
package pool12:6exported-declaration-comment
pool/context_pool.go:12:6
// Go() for the first time.type ContextPool struct { errorPool ErrorPool15:2context-stored-in-struct
pool/context_pool.go:15:2
ctx context.Context cancel context.CancelFunc24:23exported-declaration-comment
pool/context_pool.go:24:23
// are busy, a call to Go() will block until the task can be started.func (p *ContextPool) Go(f func(ctx context.Context) error) { p.errorPool.Go(func() error {39:6optimize-operands-order
pool/context_pool.go:39:6
err := f(p.ctx) if err != nil && p.cancelOnError { // Leaky abstraction warning: We add the error directly because54:23exported-declaration-comment
pool/context_pool.go:54:23
// returns an error if any of the tasks errored.func (p *ContextPool) Wait() error { // Make sure we call cancel after pool is done to avoid memory leakage.64:23exported-declaration-comment
pool/context_pool.go:64:23
// where all errors after the first are likely to be context.Canceled.func (p *ContextPool) WithFirstError() *ContextPool { p.panicIfInitialized()78:23exported-declaration-comment
pool/context_pool.go:78:23
// the first error.func (p *ContextPool) WithCancelOnError() *ContextPool { p.panicIfInitialized()87:23exported-declaration-comment
pool/context_pool.go:87:23
// the pool's context is not canceled until the parent context is canceled.func (p *ContextPool) WithFailFast() *ContextPool { p.panicIfInitialized()96:23exported-declaration-comment
pool/context_pool.go:96:23
// Defaults to unlimited. Panics if n < 1.func (p *ContextPool) WithMaxGoroutines(n int) *ContextPool { p.panicIfInitialized()pool/context_pool_test.go11
1:1format
pool/context_pool_test.go:1:1
package pool_test- Fix (safe): run `strider fmt pool/context_pool_test.go`
27:23error-strings
pool/context_pool_test.go:27:23
if i == 2 { return errors.New("I will cancel all other tasks!") }34:2discarded-error-result
pool/context_pool_test.go:34:2
err := p.Wait() fmt.Println(err) // Output:39:6cognitive-complexity
pool/context_pool_test.go:39:6
func TestContextPool(t *testing.T) { t.Parallel()39:6function-length
pool/context_pool_test.go:39:6
func TestContextPool(t *testing.T) { t.Parallel()46:46test-parallelism
pool/context_pool_test.go:46:46
t.Run("panics on configuration after init", func(t *testing.T) { t.Run("before wait", func(t *testing.T) {58:8discarded-error-result
pool/context_pool_test.go:58:8
g.Go(func(context.Context) error { return nil }) _ = g.Wait() require.Panics(t, func() { g.WithMaxGoroutines(10) })171:21nested-structs
pool/context_pool_test.go:171:21
p := pool.New().WithContext(bgctx).WithFirstError() sync := make(chan struct{}) p.Go(func(ctx context.Context) error {224:33discarded-error-result
pool/context_pool_test.go:224:33
}) assert.Panics(t, func() { _ = p.Wait() }) assert.EqualValues(t, 2, cancelledTasks.Load())231:39range-value-capture
pool/context_pool_test.go:231:39
for _, maxConcurrent := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxConcurrent), func(t *testing.T) { maxConcurrent := maxConcurrent // copy250:22redundant-conversion
pool/context_pool_test.go:250:22
require.NoError(t, p.Wait()) require.Equal(t, int64(0), currentConcurrent.Load()) })pool/error_pool.go9
1:9package-comments
pool/error_pool.go:1:9
package pool16:6exported-declaration-comment
pool/error_pool.go:16:6
// A new ErrorPool should be created using `New().WithErrors()`.type ErrorPool struct { pool Pool27:21exported-declaration-comment
pool/error_pool.go:27:21
// are busy, a call to Go() will block until the task can be started.func (p *ErrorPool) Go(f func() error) { p.pool.Go(func() {35:21exported-declaration-comment
pool/error_pool.go:35:21
// returning any errors from tasks.func (p *ErrorPool) Wait() error { p.pool.Wait()43:4no-else-after-return
pool/error_pool.go:43:4
return nil } else if p.onlyFirstError { return errs[0]45:4no-else-after-return
pool/error_pool.go:45:4
return errs[0] } else { return errors.Join(errs...)54:21exported-declaration-comment
pool/error_pool.go:54:21
// signal that all goroutines should be cancelled upon the first error.func (p *ErrorPool) WithContext(ctx context.Context) *ContextPool { p.panicIfInitialized()66:21exported-declaration-comment
pool/error_pool.go:66:21
// returned by a task. By default, Wait() will return a combined error.func (p *ErrorPool) WithFirstError() *ErrorPool { p.panicIfInitialized()74:21exported-declaration-comment
pool/error_pool.go:74:21
// Defaults to unlimited. Panics if n < 1.func (p *ErrorPool) WithMaxGoroutines(n int) *ErrorPool { p.panicIfInitialized()pool/error_pool_test.go13
1:1format
pool/error_pool_test.go:1:1
package pool_test- Fix (safe): run `strider fmt pool/error_pool_test.go`
22:23error-strings
pool/error_pool_test.go:22:23
if i == 2 { return errors.New("oh no!") }28:2discarded-error-result
pool/error_pool_test.go:28:2
err := p.Wait() fmt.Println(err) // Output:33:6cognitive-complexity
pool/error_pool_test.go:33:6
func TestErrorPool(t *testing.T) { t.Parallel()33:6function-length
pool/error_pool_test.go:33:6
func TestErrorPool(t *testing.T) { t.Parallel()39:46test-parallelism
pool/error_pool_test.go:39:46
t.Run("panics on configuration after init", func(t *testing.T) { t.Run("before wait", func(t *testing.T) {51:8discarded-error-result
pool/error_pool_test.go:51:8
g.Go(func() error { return nil }) _ = g.Wait() require.Panics(t, func() { g.WithMaxGoroutines(10) })93:34discarded-error-result
pool/error_pool_test.go:93:34
} require.Panics(t, func() { _ = g.Wait() }) })99:39range-value-capture
pool/error_pool_test.go:99:39
for _, maxGoroutines := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxGoroutines), func(t *testing.T) { g := pool.New().WithErrors().WithMaxGoroutines(maxGoroutines)99:39test-parallelism
pool/error_pool_test.go:99:39
for _, maxGoroutines := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxGoroutines), func(t *testing.T) { g := pool.New().WithErrors().WithMaxGoroutines(maxGoroutines)105:11range-value-capture
pool/error_pool_test.go:105:11
for i := 0; i < taskCount; i++ { g.Go(func() error { cur := currentConcurrent.Add(1)116:22redundant-conversion
pool/error_pool_test.go:116:22
require.NoError(t, g.Wait()) require.Equal(t, int64(0), currentConcurrent.Load()) })121:17test-parallelism
pool/error_pool_test.go:121:17
t.Run("reuse", func(t *testing.T) { // Test for https://github.com/sourcegraph/conc/issues/128pool/pool.go11
1:1format
pool/pool.go:1:1
package pool- Fix (safe): run `strider fmt pool/pool.go`
1:9package-comments
pool/pool.go:1:9
package pool30:1top-level-declaration-order
pool/pool.go:30:1
// task has an overhead of around 300ns.type Pool struct { handle conc.WaitGroup30:6exported-declaration-comment
pool/pool.go:30:6
// task has an overhead of around 300ns.type Pool struct { handle conc.WaitGroup39:16exported-declaration-comment
pool/pool.go:39:16
// are busy, a call to Go() will block until the task can be started.func (p *Pool) Go(f func()) { p.init()56:21nested-structs
pool/pool.go:56:21
select { case p.limiter <- struct{}{}: // If we are below our limit, spawn a new worker rather72:16exported-declaration-comment
pool/pool.go:72:16
// raised by a tasks.func (p *Pool) Wait() { p.init()91:16exported-declaration-comment
pool/pool.go:91:16
// Defaults to unlimited. Panics if n < 1.func (p *Pool) WithMaxGoroutines(n int) *Pool { p.panicIfInitialized()119:16exported-declaration-comment
pool/pool.go:119:16
// return errors.func (p *Pool) WithErrors() *ErrorPool { p.panicIfInitialized()140:16exported-declaration-comment
pool/pool.go:140:16
// signal that all goroutines should be cancelled upon the first error.func (p *Pool) WithContext(ctx context.Context) *ContextPool { p.panicIfInitialized()164:19nested-structs
pool/pool.go:164:19
type limiter chan struct{}pool/pool_test.go13
1:1format
pool/pool_test.go:1:1
package pool_test- Fix (safe): run `strider fmt pool/pool_test.go`
19:4discarded-error-result
pool/pool_test.go:19:4
p.Go(func() { fmt.Println("conc") })31:6cognitive-complexity
pool/pool_test.go:31:6
func TestPool(t *testing.T) { t.Parallel()31:6function-length
pool/pool_test.go:31:6
func TestPool(t *testing.T) { t.Parallel()46:38redundant-conversion
pool/pool_test.go:46:38
g.Wait() require.Equal(t, completed.Load(), int64(100)) })49:46test-parallelism
pool/pool_test.go:49:46
t.Run("panics on configuration after init", func(t *testing.T) { t.Run("before wait", func(t *testing.T) {69:39range-value-capture
pool/pool_test.go:69:39
for _, maxConcurrent := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxConcurrent), func(t *testing.T) { g := pool.New().WithMaxGoroutines(maxConcurrent)69:39test-parallelism
pool/pool_test.go:69:39
for _, maxConcurrent := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxConcurrent), func(t *testing.T) { g := pool.New().WithMaxGoroutines(maxConcurrent)76:11range-value-capture
pool/pool_test.go:76:11
for i := 0; i < taskCount; i++ { g.Go(func() { cur := currentConcurrent.Add(1)86:22redundant-conversion
pool/pool_test.go:86:22
g.Wait() require.Equal(t, int64(0), errCount.Load()) require.Equal(t, int64(0), currentConcurrent.Load())87:22redundant-conversion
pool/pool_test.go:87:22
require.Equal(t, int64(0), errCount.Load()) require.Equal(t, int64(0), currentConcurrent.Load()) })138:20redundant-conversion
pool/pool_test.go:138:20
p.Wait() require.Equal(t, int64(10), count.Load()) for i := 0; i < 10; i++ {145:20redundant-conversion
pool/pool_test.go:145:20
p.Wait() require.Equal(t, int64(20), count.Load()) })pool/result_context_pool.go10
1:1format
pool/result_context_pool.go:1:1
package pool- Fix (safe): run `strider fmt pool/result_context_pool.go`
1:9package-comments
pool/result_context_pool.go:1:9
package pool14:6exported-declaration-comment
pool/result_context_pool.go:14:6
// Go() for the first time.type ResultContextPool[T any] struct { contextPool ContextPool22:32exported-declaration-comment
pool/result_context_pool.go:22:32
// are busy, a call to Go() will block until the task can be started.func (p *ResultContextPool[T]) Go(f func(context.Context) (T, error)) { idx := p.agg.nextIndex()33:32exported-declaration-comment
pool/result_context_pool.go:33:32
// returns an error if any of the tasks errored.func (p *ResultContextPool[T]) Wait() ([]T, error) { err := p.contextPool.Wait()43:32exported-declaration-comment
pool/result_context_pool.go:43:32
// are ignored and only the error is collected.func (p *ResultContextPool[T]) WithCollectErrored() *ResultContextPool[T] { p.panicIfInitialized()51:32exported-declaration-comment
pool/result_context_pool.go:51:32
// returned by a task. By default, Wait() will return a combined error.func (p *ResultContextPool[T]) WithFirstError() *ResultContextPool[T] { p.panicIfInitialized()60:32exported-declaration-comment
pool/result_context_pool.go:60:32
// canceled until the parent context is canceled.func (p *ResultContextPool[T]) WithCancelOnError() *ResultContextPool[T] { p.panicIfInitialized()69:32exported-declaration-comment
pool/result_context_pool.go:69:32
// the pool's context is not canceled until the parent context is canceled.func (p *ResultContextPool[T]) WithFailFast() *ResultContextPool[T] { p.panicIfInitialized()77:32exported-declaration-comment
pool/result_context_pool.go:77:32
// Defaults to unlimited. Panics if n < 1.func (p *ResultContextPool[T]) WithMaxGoroutines(n int) *ResultContextPool[T] { p.panicIfInitialized()pool/result_context_pool_test.go9
1:1format
pool/result_context_pool_test.go:1:1
package pool_test- Fix (safe): run `strider fmt pool/result_context_pool_test.go`
18:6function-length
pool/result_context_pool_test.go:18:6
func TestResultContextPool(t *testing.T) { t.Parallel()24:46test-parallelism
pool/result_context_pool_test.go:24:46
t.Run("panics on configuration after init", func(t *testing.T) { t.Run("before wait", func(t *testing.T) {36:11discarded-error-result
pool/result_context_pool_test.go:36:11
g.Go(func(context.Context) (int, error) { return 0, nil }) _, _ = g.Wait() require.Panics(t, func() { g.WithMaxGoroutines(10) })140:36discarded-error-result
pool/result_context_pool_test.go:140:36
}) assert.Panics(t, func() { _, _ = p.Wait() }) assert.EqualValues(t, 2, cancelledTasks.Load())176:21nested-structs
pool/result_context_pool_test.go:176:21
g := pool.NewWithResults[int]().WithContext(context.Background()).WithFirstError() sync := make(chan struct{}) g.Go(func(ctx context.Context) (int, error) {201:40range-value-capture
pool/result_context_pool_test.go:201:40
for _, maxConcurrency := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxConcurrency), func(t *testing.T) { maxConcurrency := maxConcurrency // copy227:22redundant-conversion
pool/result_context_pool_test.go:227:22
require.NoError(t, err) require.Equal(t, int64(0), currentConcurrent.Load()) })232:17test-parallelism
pool/result_context_pool_test.go:232:17
t.Run("reuse", func(t *testing.T) { // Test for https://github.com/sourcegraph/conc/issues/128pool/result_error_pool.go10
1:1format
pool/result_error_pool.go:1:1
package pool- Fix (safe): run `strider fmt pool/result_error_pool.go`
1:9package-comments
pool/result_error_pool.go:1:9
package pool16:6exported-declaration-comment
pool/result_error_pool.go:16:6
// Go() for the first time.type ResultErrorPool[T any] struct { errorPool ErrorPool24:30exported-declaration-comment
pool/result_error_pool.go:24:30
// are busy, a call to Go() will block until the task can be started.func (p *ResultErrorPool[T]) Go(f func() (T, error)) { idx := p.agg.nextIndex()35:30exported-declaration-comment
pool/result_error_pool.go:35:30
// returning the results and any errors from tasks.func (p *ResultErrorPool[T]) Wait() ([]T, error) { err := p.errorPool.Wait()45:30exported-declaration-comment
pool/result_error_pool.go:45:30
// are ignored and only the error is collected.func (p *ResultErrorPool[T]) WithCollectErrored() *ResultErrorPool[T] { p.panicIfInitialized()55:30exported-declaration-comment
pool/result_error_pool.go:55:30
// signal that all goroutines should be cancelled upon the first error.func (p *ResultErrorPool[T]) WithContext(ctx context.Context) *ResultContextPool[T] { p.panicIfInitialized()58:16copy-lock-value
pool/result_error_pool.go:58:16
return &ResultContextPool[T]{ contextPool: *p.errorPool.WithContext(ctx), }64:30exported-declaration-comment
pool/result_error_pool.go:64:30
// returned by a task. By default, Wait() will return a combined error.func (p *ResultErrorPool[T]) WithFirstError() *ResultErrorPool[T] { p.panicIfInitialized()72:30exported-declaration-comment
pool/result_error_pool.go:72:30
// Defaults to unlimited. Panics if n < 1.func (p *ResultErrorPool[T]) WithMaxGoroutines(n int) *ResultErrorPool[T] { p.panicIfInitialized()pool/result_error_pool_test.go8
1:1format
pool/result_error_pool_test.go:1:1
package pool_test- Fix (safe): run `strider fmt pool/result_error_pool_test.go`
16:6function-length
pool/result_error_pool_test.go:16:6
func TestResultErrorPool(t *testing.T) { t.Parallel()22:46test-parallelism
pool/result_error_pool_test.go:22:46
t.Run("panics on configuration after init", func(t *testing.T) { t.Run("before wait", func(t *testing.T) {34:11discarded-error-result
pool/result_error_pool_test.go:34:11
g.Go(func() (int, error) { return 0, nil }) _, _ = g.Wait() require.Panics(t, func() { g.WithMaxGoroutines(10) })69:29nested-structs
pool/result_error_pool_test.go:69:29
g := pool.NewWithResults[int]().WithErrors().WithFirstError() synchronizer := make(chan struct{}) g.Go(func() (int, error) {107:40range-value-capture
pool/result_error_pool_test.go:107:40
for _, maxConcurrency := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxConcurrency), func(t *testing.T) { maxConcurrency := maxConcurrency // copy129:22redundant-conversion
pool/result_error_pool_test.go:129:22
require.NoError(t, err) require.Equal(t, int64(0), currentConcurrent.Load()) })134:17test-parallelism
pool/result_error_pool_test.go:134:17
t.Run("reuse", func(t *testing.T) { // Test for https://github.com/sourcegraph/conc/issues/128pool/result_pool.go16
1:1format
pool/result_pool.go:1:1
package pool- Fix (safe): run `strider fmt pool/result_pool.go`
1:9package-comments
pool/result_pool.go:1:9
package pool13:6exported-declaration-comment
pool/result_pool.go:13:6
// Go() for the first time.func NewWithResults[T any]() *ResultPool[T] { return &ResultPool[T]{15:9copy-lock-value
pool/result_pool.go:15:9
return &ResultPool[T]{ pool: *New(), }25:1top-level-declaration-order
pool/result_pool.go:25:1
// tasks were submitted.type ResultPool[T any] struct { pool Pool25:6exported-declaration-comment
pool/result_pool.go:25:6
// tasks were submitted.type ResultPool[T any] struct { pool Pool32:25exported-declaration-comment
pool/result_pool.go:32:25
// are busy, a call to Go() will block until the task can be started.func (p *ResultPool[T]) Go(f func() T) { idx := p.agg.nextIndex()41:25exported-declaration-comment
pool/result_pool.go:41:25
// a slice of results from tasks that did not panic.func (p *ResultPool[T]) Wait() []T { p.pool.Wait()55:25exported-declaration-comment
pool/result_pool.go:55:25
// can return errors.func (p *ResultPool[T]) WithErrors() *ResultErrorPool[T] { p.panicIfInitialized()58:14copy-lock-value
pool/result_pool.go:58:14
return &ResultErrorPool[T]{ errorPool: *p.pool.WithErrors(), }66:25exported-declaration-comment
pool/result_pool.go:66:25
// signal that all goroutines should be cancelled upon the first error.func (p *ResultPool[T]) WithContext(ctx context.Context) *ResultContextPool[T] { p.panicIfInitialized()69:16copy-lock-value
pool/result_pool.go:69:16
return &ResultContextPool[T]{ contextPool: *p.pool.WithContext(ctx), }75:25exported-declaration-comment
pool/result_pool.go:75:25
// Defaults to unlimited. Panics if n < 1.func (p *ResultPool[T]) WithMaxGoroutines(n int) *ResultPool[T] { p.panicIfInitialized()89:2redefines-builtin-id
pool/result_pool.go:89:2
mu sync.Mutex len int results []T105:50flag-parameter
pool/result_pool.go:105:50
func (r *resultAggregator[T]) save(i int, res T, errored bool) { r.mu.Lock()123:39flag-parameter
pool/result_pool.go:123:39
// collect returns the set of aggregated results.func (r *resultAggregator[T]) collect(collectErrored bool) []T { if !r.mu.TryLock() {pool/result_pool_test.go11
1:1format
pool/result_pool_test.go:1:1
package pool_test- Fix (safe): run `strider fmt pool/result_pool_test.go`
25:2discarded-error-result
pool/result_pool_test.go:25:2
res := p.Wait() fmt.Println(res)31:6cognitive-complexity
pool/result_pool_test.go:31:6
func TestResultGroup(t *testing.T) { t.Parallel()31:6function-length
pool/result_pool_test.go:31:6
func TestResultGroup(t *testing.T) { t.Parallel()34:46test-parallelism
pool/result_pool_test.go:34:46
t.Run("panics on configuration after init", func(t *testing.T) { t.Run("before wait", func(t *testing.T) {89:39range-value-capture
pool/result_pool_test.go:89:39
for _, maxGoroutines := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxGoroutines), func(t *testing.T) { g := pool.NewWithResults[int]().WithMaxGoroutines(maxGoroutines)89:39test-parallelism
pool/result_pool_test.go:89:39
for _, maxGoroutines := range []int{1, 10, 100} { t.Run(strconv.Itoa(maxGoroutines), func(t *testing.T) { g := pool.NewWithResults[int]().WithMaxGoroutines(maxGoroutines)99:11range-value-capture
pool/result_pool_test.go:99:11
expected[i] = i g.Go(func() int { cur := currentConcurrent.Add(1)111:22redundant-conversion
pool/result_pool_test.go:111:22
require.Equal(t, expected, res) require.Equal(t, int64(0), errCount.Load()) require.Equal(t, int64(0), currentConcurrent.Load())112:22redundant-conversion
pool/result_pool_test.go:112:22
require.Equal(t, int64(0), errCount.Load()) require.Equal(t, int64(0), currentConcurrent.Load()) })117:17test-parallelism
pool/result_pool_test.go:117:17
t.Run("reuse", func(t *testing.T) { // Test for https://github.com/sourcegraph/conc/issues/128stream/stream.go12
1:1format
stream/stream.go:1:1
// Package stream provides a concurrent, ordered stream implementation.package stream- Fix (safe): run `strider fmt stream/stream.go`
15:9copy-lock-value
stream/stream.go:15:9
return &Stream{ pool: *pool.New(), }38:1top-level-declaration-order
stream/stream.go:38:1
// good enough for any task that requires a network call.type Stream struct { pool pool.Pool38:6exported-declaration-comment
stream/stream.go:38:6
// good enough for any task that requires a network call.type Stream struct { pool pool.Pool39:2import-shadowing
stream/stream.go:39:2
type Stream struct { pool pool.Pool callbackerHandle conc.WaitGroup49:6exported-declaration-comment
stream/stream.go:49:6
// the task has completed.type Task func() Callback53:6exported-declaration-comment
stream/stream.go:53:6
// called in the same order that tasks are submitted.type Callback func()62:18exported-declaration-comment
stream/stream.go:62:18
// started.func (s *Stream) Go(f Task) { s.init()91:18exported-declaration-comment
stream/stream.go:91:18
// not return until all tasks and callbacks have been run.func (s *Stream) Wait() { s.init()105:18exported-declaration-comment
stream/stream.go:105:18
func (s *Stream) WithMaxGoroutines(n int) *Stream { s.pool.WithMaxGoroutines(n)142:5no-package-var
stream/stream.go:142:5
var callbackChPool = sync.Pool{ New: func() any {149:29unchecked-type-assertion
stream/stream.go:149:29
func getCh() callbackCh { return callbackChPool.Get().(callbackCh)}stream/stream_test.go5
1:1format
stream/stream_test.go:1:1
package stream_test- Fix (safe): run `strider fmt stream/stream_test.go`
23:20discarded-error-result
stream/stream_test.go:23:20
// This will print in the order the tasks were submitted return func() { fmt.Println(dur) } })37:6cognitive-complexity
stream/stream_test.go:37:6
func TestStream(t *testing.T) { t.Parallel()37:6function-length
stream/stream_test.go:37:6
func TestStream(t *testing.T) { t.Parallel()68:20redundant-conversion
stream/stream_test.go:68:20
s.Wait() require.Equal(t, int64(5), totalCount.Load()) })waitgroup.go6
1:1format
waitgroup.go:1:1
package conc- Fix (safe): run `strider fmt waitgroup.go`
1:9package-comments
waitgroup.go:1:9
package conc22:1top-level-declaration-order
waitgroup.go:22:1
// Also like sync.WaitGroup, it must not be copied after first use.type WaitGroup struct { wg sync.WaitGroup22:6exported-declaration-comment
waitgroup.go:22:6
// Also like sync.WaitGroup, it must not be copied after first use.type WaitGroup struct { wg sync.WaitGroup38:21exported-declaration-comment
waitgroup.go:38:21
// propagate any panics spawned in a child goroutine.func (h *WaitGroup) Wait() { h.wg.Wait()47:21exported-declaration-comment
waitgroup.go:47:21
// will return a *panics.Recovered if one of the child goroutines panics.func (h *WaitGroup) WaitAndRecover() *panics.Recovered { h.wg.Wait()waitgroup_test.go8
1:1format
waitgroup_test.go:1:1
package conc_test- Fix (safe): run `strider fmt waitgroup_test.go`
24:2discarded-error-result
waitgroup_test.go:24:2
fmt.Println(count.Load()) // Output:37:2discarded-error-result
waitgroup_test.go:37:2
recoveredPanic := wg.WaitAndRecover() fmt.Println(recoveredPanic.Value) // Output:42:6function-length
waitgroup_test.go:42:6
func TestWaitGroup(t *testing.T) { t.Parallel()61:34redundant-conversion
waitgroup_test.go:61:34
wg.Wait() require.Equal(t, count.Load(), int64(100)) })80:11add-constant
waitgroup_test.go:80:11
wg.Go(func() { panic("super bad thing") })114:21redundant-conversion
waitgroup_test.go:114:21
require.Panics(t, wg.Wait) require.Equal(t, int64(2), i.Load()) })155:21redundant-conversion
waitgroup_test.go:155:21
require.Equal(t, p.Value, "super bad thing") require.Equal(t, int64(2), i.Load()) })