New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
GOExample pasteCreated 2026-07-311 viewNo expiry

Go worker pool with cancellation

Raw New paste
goRead-only
1
func worker(ctx context.Context, jobs <-chan Job, results chan<- Result) {
    for {
        select {
        case <-ctx.Done():
            return
        case job, ok := <-jobs:
            if !ok {
                return
            }
            result := process(job)
            select {
            case results <- result:
            case <-ctx.Done():
                return
            }
        }
    }
}
Report abuse

Paste details

Visibility
Public
Size
415 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.