syncx

package
v0.4.0 Latest Latest
Warning

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

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

README

syncx 包 Package

syncx 提供 context-aware semaphore limiter 和首错取消的 worker group。

Use the limiter for bounded concurrency and WorkerGroup when the first worker error should cancel siblings.

Documentation

Overview

Package syncx 提供上下文感知并发限制和工作组。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter interface {
	Acquire(context.Context) error
	Release()
}

type SemaphoreLimiter

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

func NewSemaphoreLimiter

func NewSemaphoreLimiter(n int) *SemaphoreLimiter
Example
package main

import (
	"context"

	"github.com/ZoneCNH/kernel/syncx"
)

func main() {
	limiter := syncx.NewSemaphoreLimiter(2)
	_ = limiter.Acquire(context.Background())
	limiter.Release()
}

func (*SemaphoreLimiter) Acquire

func (l *SemaphoreLimiter) Acquire(ctx context.Context) error

func (*SemaphoreLimiter) Release

func (l *SemaphoreLimiter) Release()

type WorkerGroup

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

func NewWorkerGroup

func NewWorkerGroup(ctx context.Context) *WorkerGroup

func (*WorkerGroup) Go

func (g *WorkerGroup) Go(fn func(context.Context) error)

func (*WorkerGroup) Wait

func (g *WorkerGroup) Wait() error

Jump to

Keyboard shortcuts

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