go-concurrency_skill

This skill helps you write safe, efficient Go concurrency patterns using goroutines, channels, context, and sync primitives.

0

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill jovermier/cc-stack-marketplace --skill go-concurrency

  • SKILL.md3.4 KB

Overview

This skill provides expert guidance for writing safe, leak-free concurrent Go code. It focuses on goroutine lifecycle, channel idioms, context propagation, and sync primitives to help prevent leaks, races, and deadlocks. Use it to harden and review concurrent Go routines and patterns in real code.

How this skill works

The skill inspects concurrent code patterns and recommends concrete corrections: ensuring goroutines have exit paths, validating context is passed first and canceled, checking channel ownership and closing patterns, and verifying proper use of sync primitives like Mutex, RWMutex, WaitGroup, and errgroup. It highlights common pitfalls, suggests fixes (select on ctx.Done(), defer cancel(), Add/Done ordering), and points to the appropriate pattern depending on the issue.

When to use it

  • When adding or reviewing goroutines or worker pools
  • When using channels for signaling or streaming data
  • When propagating cancellation and deadlines via context.Context
  • When synchronizing access to shared state with Mutex/RWMutex
  • When handling errors across concurrent goroutines (errgroup)

Best practices

  • Always include a known exit path for every goroutine; select on ctx.Done() for cancellation
  • Make context.Context the first function parameter and always defer cancel() after WithCancel/WithTimeout
  • Only the sender closes channels; receivers should handle closed channels safely (check ok on receive)
  • Use sync.Mutex or sync.RWMutex for mutual exclusion; don’t use buffered channels as mutexes
  • Call wg.Add() before starting goroutines and defer wg.Done() inside each goroutine; prefer errgroup.Group when collecting errors

Example use cases

  • Convert unbounded goroutine spawns into a bounded worker pool with context cancellation
  • Fix a goroutine leak by adding ctx.Done() select case and ensuring defer cancel() propagates
  • Replace a buffered-channel-as-mutex pattern with sync.Mutex to remove races
  • Use errgroup.Group to run parallel HTTP requests and return the first error while canceling remaining work
  • Add context to deep call stacks so timeouts and cancellation propagate cleanly

FAQ

Prefer using context cancellation and rewrite blocking operations to respect ctx.Done(). If the blocking call is external, use timeouts or cancelable APIs where possible.

When should I use errgroup vs WaitGroup?

Use errgroup.Group when you need to collect and propagate the first error and cancel sibling goroutines. Use sync.WaitGroup when you only need to wait for completion without error aggregation.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
go-concurrency skill by jovermier/cc-stack-marketplace | VeilStrat