Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names

Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
This commit is contained in:
bwilliams committed 2026-10-15 16:12:56 +01:00
1 parent 043e307663
commit 465358609a
78 files changed
+2374 -1402

No files matched your search

+15 -12
View File
@@ -135,26 +135,29 @@ func (w Worker) execute(
}
}
// AwaitTask runs fn in its own goroutine and returns its result, or ctx.Err()
// AwaitTask runs task in its own goroutine and returns its result, or ctx.Err()
// if ctx is cancelled first. This lets a Task stop waiting on a call that does
// not respond promptly to cancellation.
//
// The result channel is buffered, so if ctx wins the race the goroutine can
// still deliver its result and exit instead of blocking forever.
func AwaitTask[T any](ctx context.Context, fn func() (T, error)) (T, error) {
func AwaitTask[T any](ctx context.Context, task func() (T, error)) (T, error) {
type result struct {
val T
err error
}
ch := make(chan result, 1)
results := make(chan result, 1)
go func() {
val, err := fn()
ch <- result{val, err}
value, err := task()
results <- result{
val: value,
err: err,
}
}()
select {
case r := <-ch:
return r.val, r.err
case result := <-results:
return result.val, result.err
case <-ctx.Done():
var zero T
return zero, ctx.Err()
@@ -162,15 +165,15 @@ func AwaitTask[T any](ctx context.Context, fn func() (T, error)) (T, error) {
}
// AwaitTaskE is AwaitTask for a function that returns only an error.
func AwaitTaskE(ctx context.Context, fn func() error) error {
ch := make(chan error, 1)
func AwaitTaskE(ctx context.Context, task func() error) error {
results := make(chan error, 1)
go func() {
err := fn()
ch <- err
err := task()
results <- err
}()
select {
case err := <-ch:
case err := <-results:
return err
case <-ctx.Done():
return ctx.Err()