goroutines

go
package workpool

import (
	"context"
	"sync"
)

Bounded Worker Pool Processing Jobs from a Buffered Channel in Go

go concurrency worker-pool
by codesnips 3 tabs
go
package pipeline

import "context"

func generate(ctx context.Context, nums ...int) <-chan int {
	out := make(chan int)

Fan-Out/Fan-In Pipeline With Channels and Context Cancellation in Go

go concurrency channels
by codesnips 3 tabs
go
package worker

import "context"

func (p *Pool) Submit(job Job) error {
	// Reject fast if draining, otherwise enqueue with backpressure.

Graceful Drain of In-Flight Jobs Before Worker Shutdown in Go

go graceful-shutdown concurrency
by codesnips 3 tabs
go
package scheduler

import (
	"context"
	"log"
	"sync"

Graceful Cron-Style Scheduler in Go With Ticker and Context Cancellation

scheduler ticker context
by codesnips 3 tabs
go
package sse

type Broker struct {
	subscribers map[chan []byte]struct{}
	subscribe   chan chan []byte
	unsubscribe chan chan []byte

Server-Sent Events in Go with http.Flusher and Context Cancellation

sse streaming http
by codesnips 3 tabs
go
package limiter

import (
	"context"
	"errors"
)

Leaky-Bucket Concurrency Limiter with a Buffered Semaphore Channel in Go

go concurrency rate-limiting
by codesnips 3 tabs
go
package watch

import (
	"sync"
	"time"
)

Debounce Filesystem Change Events Before Triggering a Rebuild in Go

fsnotify debounce filewatcher
by codesnips 3 tabs
go
package main

import (
	"context"
	"log"
	"net/http"

Graceful HTTP Server Shutdown in Go with SIGINT and Context Cancellation

go http graceful-shutdown
by codesnips 2 tabs
go
package pricecache

import (
	"context"
	"sync"

Collapse Concurrent Identical Requests in Go with singleflight

go singleflight concurrency
by codesnips 3 tabs
go
package apiclient

import (
	"context"
	"fmt"
	"io"

Sharing a golang.org/x/time/rate Limiter Across Goroutines for Outbound API Calls

go rate-limiting concurrency
by codesnips 3 tabs
go
package fetch

import (
	"context"
	"net/http"

Bounded Fan-Out With Worker Pool, errgroup, and Result Collection in Go

go concurrency goroutines
by codesnips 3 tabs
go
package hub

type Hub struct {
	subscribers map[*Subscriber]struct{}
	broadcast   chan []byte
	register    chan registration

Concurrent Fan-Out Event Hub With Non-Blocking Broadcast in Go

go concurrency channels
by codesnips 3 tabs