Skip to content

Yu-Jack/go-concurrency-patterns

Repository files navigation

Introduction

This repo demos for golang concurrency patterns after read Concurrency in Go. There are something I modified in these examples.

  1. Buffered or unbuffered channel both are okay, it doesn't have effect in these examples. But for memory efficiency, I choose unbuffered channel.
  2. I reorder the pattern for easily learning based on my opinion. So there might be some differences between repo and book.
  3. In each example, it will print expected 1 goroutine, got goroutine: 1. That means the program close all goroutines safely (except main goroutine) to avoid goroutine leaks.

There is an simple introduction article written in Chinese. Feel free to read it.

Outline

Concurrency Pattern
01: Generator
02: Done channel
03: Pipeline
04: Fan-In
05: Fan-Out
06: Fan-In and Fan-Out
07: Or-Channel
08: Or-Done-Channel
09: Tee-Channel
10: Bridge-Channel

Related Usage

These examples are built with above related concepts.

Other Usage
01: Graceful Shutdown
02: Pub/Sub
03: Worker Pool

References

  1. Concurrency in Go.

About

Project for golang concurrency patterns

Topics

Resources

Stars

Watchers

Forks

Languages