Skip to content

Bright98/go-concurrency-patterns

Repository files navigation

Golang Concurrency Patterns

go-logo

This repository serves as a collection of Golang concurrency patterns, and some examples. It aims to provide developers with a reference for understanding and implementing concurrency in Go.

Table of Contents

Introduction

Concurrency is a key feature of the Go programming language, allowing developers to write efficient and scalable programs. This repository focuses on providing practical examples and explanations for various concurrency patterns in Go.

Concurrency Patterns

1. Wait for result

In some scenarios, you may need to wait for the result of a specific goroutine. This can be achieved using channels or other synchronization mechanisms.

view code

2. Wait for task

Use a combination of goroutines and channels to implement a task queue. Workers can pick up tasks and process them concurrently.

view code

3. Fan-out, Fan-in

Fan-out involves starting multiple goroutines to handle incoming data, and fan-in merges their results into a single channel.

view code

4. Pooling

Pooling is a common pattern where a fixed number of worker goroutines are created to handle tasks from a shared queue.

view code

5. Drop

In some scenarios, you may want to drop tasks if the processing capacity is exceeded. This can be achieved by using a buffered channel.

view code

6. Cancellation

Implement cancellation of goroutines using the context package. This allows for the graceful termination of concurrent tasks.

view code

About

My Golang concurrency patterns practice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages