syncprim

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package syncprim provides Semaphore and Once built on fenced claim primitives.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnavailable = errors.New("syncprim: unavailable")
	ErrNotHeld     = errors.New("syncprim: not held")
)

Functions

This section is empty.

Types

type FencedClaims

type FencedClaims interface {
	Acquire(ctx context.Context, claim string) (token uint64, err error)
	Release(ctx context.Context, claim string, token uint64) error
}

FencedClaims acquires named claims with fencing tokens.

type Once

type Once struct {
	// contains filtered or unexported fields
}

Once ensures a single fenced execution of fn across participants.

func NewOnce

func NewOnce(claims FencedClaims, claimName string) (*Once, error)

NewOnce creates a claim-backed Once.

func (*Once) Do

func (o *Once) Do(ctx context.Context, fn func(ctx context.Context, token uint64) error) error

Do acquires the claim, runs fn once locally if acquired, then releases. If the claim is held elsewhere, returns ErrUnavailable without running fn.

type Semaphore

type Semaphore struct {
	// contains filtered or unexported fields
}

Semaphore bounds concurrent holders using one claim name per permit slot.

func NewSemaphore

func NewSemaphore(claims FencedClaims, namePrefix string, n int) (*Semaphore, error)

NewSemaphore creates a semaphore with n permits (n > 0, bounded).

func (*Semaphore) Acquire

func (s *Semaphore) Acquire(ctx context.Context) (release func(context.Context) error, err error)

Acquire obtains one permit (fencing per permit).

Jump to

Keyboard shortcuts

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