Skip to content
Skillpedia
General coding41k · #4965

go-concurrency-patterns

Helps your agent use advanced concurrency features in Go. It allows for building faster and more efficient programs by handling multiple tasks simultaneously.

What it does

This tool helps you understand and use advanced ways to do multiple things at the same time in a Go computer program. It teaches you how to use 'goroutines' (small tasks that run together) and 'channels' (communication lines between these tasks).

When to use it

  • ✓When building Go programs that need to do multiple things concurrently.
  • ✓When organizing tasks to work together efficiently (like in 'worker pools').
  • ✓When trying to figure out why your program is crashing or having concurrency errors.

Example of what to ask your AI

“How can I make two parts of my Go program run at the same time and exchange information safely?”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/wshobson/agents/blob/main/plugins/systems-programming/skills/go-concurrency-patterns/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/wshobson/agents/blob/main/plugins/systems-programming/skills/go-concurrency-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

It explains the basic building blocks of concurrency in Go, like 'goroutines' and 'channels', and shows examples of how to use them for communication and synchronization.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add wshobson/agents --skill go-concurrency-patterns

Or download just the file:

curl -L https://raw.githubusercontent.com/wshobson/agents/main/plugins/systems-programming/skills/go-concurrency-patterns/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Go Concurrency Patterns

Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management.

When to Use This Skill

  • Building concurrent Go applications
  • Implementing worker pools and pipelines
  • Managing goroutine lifecycles
  • Using channels for communication
  • Debugging race conditions
  • Implementing graceful shutdown

Core Concepts

1. Go Concurrency Primitives

Primitive Purpose
goroutine Lightweight concurrent execution
channel Communication between goroutines
select Multiplex channel operations
sync.Mutex Mutual exclusion
sync.WaitGroup Wait for goroutines to complete
context.Context Cancellation and deadlines

2. Go Concurrency Mantra

Don't communicate by sharing memory;
share memory by communicating.

Quick Start

package main

import (
    "context"
    "fmt"
    "sync"
    "time"
)

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    results := make(chan string, 10)
    var wg sync.WaitGroup

    // Spawn workers
    for i := 0; i < 3; i++ {
        wg.Add(1)
        go worker(ctx, i, results, &wg)
    }

    // Close results when done
    go func() {
        wg.Wait()
        close(results)
    }()

    // Collect results
    for result := range results {
        fmt.Println(result)
    }
}

func worker(ctx context.Context, id int, results chan<- string, wg *sync.WaitGroup) {
    defer wg.Done()

    select {
    case <-ctx.Done():
        return
    case results <- fmt.Sprintf("Worker %d done", id):
    }
}

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Use context - For cancellation and deadlines
  • Close channels - From sender side only
  • Use errgroup - For concurrent operations with errors
  • Buffer channels - When you know the count
  • Prefer channels - Over mutexes when possible

Don'ts

  • Don't leak goroutines - Always have exit path
  • Don't close from receiver - Causes panic
  • Don't use shared memory - Unless necessary
  • Don't ignore context cancellation - Check ctx.Done()
  • Don't use time.Sleep for sync - Use proper primitives
FAQ

What is a 'goroutine'?

It's like a function that can run at the same time as other parts of your program, without interfering.

What are 'channels' for?

They are like pipes through which 'goroutines' can send and receive messages to each other safely.

What does 'Don't communicate by sharing memory; share memory by communicating' mean?

It's advice to avoid having multiple parts of your program access the same data at the same time (which can cause errors). Instead, use 'channels' to pass data between them.

Details

Original description by the author

Master Go concurrency with goroutines, channels, sync primitives, and context. Use when building concurrent Go applications, implementing worker pools, or debugging race conditions.

repo: wshobson/agents

Popularity

GitHub stars
41k
Ranking position
#4965
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills