Documentation
¶
Overview ¶
Package syncx 提供上下文感知并发限制和工作组。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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()
}
Output:
func (*SemaphoreLimiter) Release ¶
func (l *SemaphoreLimiter) Release()
Release returns a permit to the limiter. Double-release when no permit is held is silently ignored; this is a deliberate design choice to simplify caller cleanup paths.
func (*SemaphoreLimiter) TryRelease ¶ added in v0.6.0
func (l *SemaphoreLimiter) TryRelease() bool
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)
Go 启动一个 worker goroutine。如果 WorkerGroup 已被 Wait 关闭,调用被静默忽略。 如需检测关闭状态,使用 TryGo。
func (*WorkerGroup) TryGo ¶ added in v0.6.0
func (g *WorkerGroup) TryGo(fn func(context.Context) error) bool
func (*WorkerGroup) Wait ¶
func (g *WorkerGroup) Wait() error
Click to show internal directories.
Click to hide internal directories.