sync

package
v2.303.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sync provides synchronization primitives and pooling helpers used by go-service.

This package intentionally offers a small, stable API surface that wraps:

  • The standard library sync primitives (for example Mutex and RWMutex).
  • A small set of additional concurrency-safe utilities from the external module github.com/alexfalkowski/go-sync (for example a generic Map and a byte buffer pool).

The goal is to let go-service code depend on go-service packages consistently, while still using well-known synchronization patterns and implementations.

Standard library wrappers

This package re-exports common mutex types as aliases:

  • Mutex (alias of sync.Mutex)
  • RWMutex (alias of sync.RWMutex)

Because these are type aliases, they have the same semantics and methods as the standard library types.

Generic concurrent map

Map and NewMap are aliases/wrappers around github.com/alexfalkowski/go-sync's generic concurrent map implementation:

  • Map[K, V] is a concurrent map keyed by K with values V.
  • NewMap[K, V] constructs a new instance.

Consult the upstream go-sync documentation for details of the map’s method set and concurrency guarantees.

Buffer pool

BufferPool and NewBufferPool are aliases/wrappers around github.com/alexfalkowski/go-sync's buffer pool implementation:

  • BufferPool provides pooled buffers to reduce allocations in hot paths.
  • NewBufferPool constructs a new pool.

Buffer pools are typically used by transports/encoders to reuse temporary buffers when assembling payloads.

Dependency injection (Fx)

This package also exports Module, which wires the buffer pool into Fx. Including Module in an Fx application provides a shared *BufferPool instance constructed via the upstream go-sync constructor.

Notes

This package does not attempt to replace the standard library sync package. If you need primitives not exposed here, prefer importing sync directly.

Index

Constants

This section is empty.

Variables

Module wires a shared buffer pool into Fx.

Including this module in an Fx application provides a single, shared *BufferPool instance constructed via github.com/alexfalkowski/go-sync.NewBufferPool.

This is commonly used to reduce allocations across components that build or transform byte payloads (for example encoders, compressors, and transports) by reusing temporary buffers.

Note: the concrete BufferPool type and its lifecycle/usage contract are defined by the upstream go-sync package.

Functions

This section is empty.

Types

type BufferPool

type BufferPool = sync.BufferPool

BufferPool provides pooled buffers to reduce allocations.

BufferPool is a type alias of github.com/alexfalkowski/go-sync.BufferPool. Because it is an alias, its behavior, method set, and performance characteristics are those of the upstream implementation.

func NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool constructs a new BufferPool.

This function forwards to github.com/alexfalkowski/go-sync.NewBufferPool and returns a *BufferPool (which is a type alias of the upstream implementation).

Buffer pools are typically used to reduce allocations in hot paths that build byte payloads (for example encoders, compressors, and transports) by reusing temporary buffers across operations.

Consult the upstream go-sync documentation for details of the pool’s API and usage expectations (for example how buffers are acquired/reset/released).

type Map added in v2.260.0

type Map[K comparable, V any] = sync.Map[K, V]

Map is a generic concurrency-safe map keyed by K with values of type V.

Map is a type alias of github.com/alexfalkowski/go-sync.Map. Because it is an alias, its behavior, method set, and performance characteristics are those of the upstream implementation.

If you need semantics beyond what the upstream Map provides (for example custom eviction policies or strong iteration guarantees), use a different data structure or explicit locking with Mutex/RWMutex.

func NewMap added in v2.269.0

func NewMap[K comparable, V any]() Map[K, V]

NewMap constructs a new concurrent Map. // // This function forwards to github.com/alexfalkowski/go-sync.NewMap and returns // a Map[K, V] (which is a type alias of the upstream implementation). // // Use Map when you need a concurrency-safe key/value store without manually // managing locks. The exact method set and concurrency guarantees are defined // by the upstream go-sync package.

type Mutex

type Mutex = sync.Mutex

Mutex is a mutual exclusion lock.

Mutex is a type alias of github.com/alexfalkowski/go-sync.Mutex (which in turn is expected to mirror the semantics of the standard library sync.Mutex).

Use Mutex to protect shared state that must not be accessed concurrently. The zero value is usable without initialization.

type RWMutex

type RWMutex = sync.RWMutex

RWMutex is a reader/writer mutual exclusion lock.

RWMutex is a type alias of github.com/alexfalkowski/go-sync.RWMutex (which in turn is expected to mirror the semantics of the standard library sync.RWMutex).

A RWMutex allows concurrent readers or a single writer. Use RWMutex when reads are frequent and can safely proceed in parallel, while writes must be exclusive. The zero value is usable without initialization.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL