Loading documentation...
Loading documentation...
Loading documentation...
Complete API documentation for the semaphore package.
Import Path: github.com/kolosys/ion/semaphore
Package semaphore provides a weighted semaphore with configurable fairness modes.
ErrInvalidWeight
Common sentinel errors for semaphore operations
var ErrInvalidWeight = errors.New("ion: invalid weight, must be positive") // ErrInvalidWeight is returned when a negative or zero weight is provided to semaphore operations
Fairness defines the ordering behavior for semaphore waiters
// Example usage of Fairness
var value Fairness
// Initialize with appropriate valuetype Fairness intString returns the string representation of the fairness mode
func (Fairness) String() stringParameters: None
Returns:
Option configures semaphore behavior
// Example usage of Option
var value Option
// Initialize with appropriate valuetype Option func(*config)WithAcquireTimeout sets the default timeout for Acquire operations
func WithAcquireTimeout(timeout time.Duration) OptionParameters:
timeout (time.Duration)Returns:
WithFairness sets the fairness mode for waiter ordering
func WithFairness(fairness Fairness) OptionParameters:
fairness (Fairness)Returns:
WithLogger sets the logger for observability
func WithLogger(logger observe.Logger) OptionParameters:
logger (observe.Logger)Returns:
WithMetrics sets the metrics recorder for observability
func WithMetrics(metrics observe.Metrics) OptionParameters:
metrics (observe.Metrics)Returns:
WithName sets the semaphore name for observability and error reporting
func WithName(name string) OptionParameters:
name (string)Returns:
WithTracer sets the tracer for observability
func WithTracer(tracer observe.Tracer) OptionParameters:
tracer (observe.Tracer)Returns:
Semaphore represents a weighted semaphore that controls access to a resource with a fixed capacity. It supports configurable fairness modes and observability.
// Example implementation of Semaphore
type MySemaphore struct {
// Add your fields here
}
func (m MySemaphore) Acquire(param1 context.Context, param2 int64) error {
// Implement your logic here
return
}
func (m MySemaphore) TryAcquire(param1 int64) bool {
// Implement your logic here
return
}
func (m MySemaphore) Release(param1 int64) {
// Implement your logic here
return
}
func (m MySemaphore) Current() int64 {
// Implement your logic here
return
}
type Semaphore interface {
Acquire(ctx context.Context, n int64) error
TryAcquire(n int64) bool
Release(n int64)
Current() int64
}| Method | Description |
|---|
NewWeighted creates a new weighted semaphore with the specified capacity. The semaphore starts with all permits available.
func NewWeighted(capacity int64, opts ...Option) SemaphoreParameters:
capacity (int64)opts (...Option)Returns:
SemaphoreError represents semaphore-specific errors with context
// Create a new SemaphoreError
semaphoreerror := SemaphoreError{
Op: "example",
Name: "example",
Err: error{},
}type SemaphoreError struct {
Op string
Name string
Err error
}| Field | Type | Description |
|---|---|---|
| Op | string | operation that failed |
| Name | string | name of the semaphore |
| Err | error | underlying error |
func (*SemaphoreError) Error() stringParameters: None
Returns:
func (*SemaphoreError) Unwrap() errorParameters: None
Returns:
NewAcquireTimeoutError creates an error indicating an acquire operation timed out
func NewAcquireTimeoutError(semaphoreName string) errorParameters:
| Parameter | Type | Description |
|---|---|---|
semaphoreName | string |
Returns:
| Type | Description |
|---|---|
error |
Example:
// Example usage of NewAcquireTimeoutError
result := NewAcquireTimeoutError(/* parameters */)NewWeightExceedsCapacityError creates an error indicating the requested weight exceeds capacity
func NewWeightExceedsCapacityError(semaphoreName string, weight, capacity int64) errorParameters:
| Parameter | Type | Description |
|---|---|---|
semaphoreName | string | |
weight | int64 | |
capacity | int64 |
Returns:
| Type | Description |
|---|---|
error |
Example:
// Example usage of NewWeightExceedsCapacityError
result := NewWeightExceedsCapacityError(/* parameters */)Complete API documentation for the semaphore package.
Import Path: github.com/kolosys/ion/semaphore
Package semaphore provides a weighted semaphore with configurable fairness modes.
ErrInvalidWeight
Common sentinel errors for semaphore operations
var ErrInvalidWeight = errors.New("ion: invalid weight, must be positive") // ErrInvalidWeight is returned when a negative or zero weight is provided to semaphore operations
Fairness defines the ordering behavior for semaphore waiters
// Example usage of Fairness
var value Fairness
// Initialize with appropriate valuetype Fairness intString returns the string representation of the fairness mode
func (Fairness) String() stringParameters: None
Returns:
Option configures semaphore behavior
// Example usage of Option
var value Option
// Initialize with appropriate valuetype Option func(*config)WithAcquireTimeout sets the default timeout for Acquire operations
func WithAcquireTimeout(timeout time.Duration) OptionParameters:
timeout (time.Duration)Returns:
WithFairness sets the fairness mode for waiter ordering
func WithFairness(fairness Fairness) OptionParameters:
fairness (Fairness)Returns:
WithLogger sets the logger for observability
func WithLogger(logger observe.Logger) OptionParameters:
logger (observe.Logger)Returns:
WithMetrics sets the metrics recorder for observability
func WithMetrics(metrics observe.Metrics) OptionParameters:
metrics (observe.Metrics)Returns:
WithName sets the semaphore name for observability and error reporting
func WithName(name string) OptionParameters:
name (string)Returns:
WithTracer sets the tracer for observability
func WithTracer(tracer observe.Tracer) OptionParameters:
tracer (observe.Tracer)Returns:
Semaphore represents a weighted semaphore that controls access to a resource with a fixed capacity. It supports configurable fairness modes and observability.
// Example implementation of Semaphore
type MySemaphore struct {
// Add your fields here
}
func (m MySemaphore) Acquire(param1 context.Context, param2 int64) error {
// Implement your logic here
return
}
func (m MySemaphore) TryAcquire(param1 int64) bool {
// Implement your logic here
return
}
func (m MySemaphore) Release(param1 int64) {
// Implement your logic here
return
}
func (m MySemaphore) Current() int64 {
// Implement your logic here
return
}
type Semaphore interface {
Acquire(ctx context.Context, n int64) error
TryAcquire(n int64) bool
Release(n int64)
Current() int64
}| Method | Description |
|---|
NewWeighted creates a new weighted semaphore with the specified capacity. The semaphore starts with all permits available.
func NewWeighted(capacity int64, opts ...Option) SemaphoreParameters:
capacity (int64)opts (...Option)Returns:
SemaphoreError represents semaphore-specific errors with context
// Create a new SemaphoreError
semaphoreerror := SemaphoreError{
Op: "example",
Name: "example",
Err: error{},
}type SemaphoreError struct {
Op string
Name string
Err error
}| Field | Type | Description |
|---|---|---|
| Op | string | operation that failed |
| Name | string | name of the semaphore |
| Err | error | underlying error |
func (*SemaphoreError) Error() stringParameters: None
Returns:
func (*SemaphoreError) Unwrap() errorParameters: None
Returns:
NewAcquireTimeoutError creates an error indicating an acquire operation timed out
func NewAcquireTimeoutError(semaphoreName string) errorParameters:
| Parameter | Type | Description |
|---|---|---|
semaphoreName | string |
Returns:
| Type | Description |
|---|---|
error |
Example:
// Example usage of NewAcquireTimeoutError
result := NewAcquireTimeoutError(/* parameters */)NewWeightExceedsCapacityError creates an error indicating the requested weight exceeds capacity
func NewWeightExceedsCapacityError(semaphoreName string, weight, capacity int64) errorParameters:
| Parameter | Type | Description |
|---|---|---|
semaphoreName | string | |
weight | int64 | |
capacity | int64 |
Returns:
| Type | Description |
|---|---|
error |
Example:
// Example usage of NewWeightExceedsCapacityError
result := NewWeightExceedsCapacityError(/* parameters */)var ErrInvalidWeight = errors.New("ion: invalid weight, must be positive") // ErrInvalidWeight is returned when a negative or zero weight is provided to semaphore operations
// Example usage of Fairness
var value Fairness
// Initialize with appropriate valuetype Fairness intfunc (Fairness) String() string// Example usage of Option
var value Option
// Initialize with appropriate valuetype Option func(*config)func WithAcquireTimeout(timeout time.Duration) Optionfunc WithFairness(fairness Fairness) Optionfunc WithLogger(logger observe.Logger) Optionfunc WithMetrics(metrics observe.Metrics) Optionfunc WithName(name string) Optionfunc WithTracer(tracer observe.Tracer) Option// Example implementation of Semaphore
type MySemaphore struct {
// Add your fields here
}
func (m MySemaphore) Acquire(param1 context.Context, param2 int64) error {
// Implement your logic here
return
}
func (m MySemaphore) TryAcquire(param1 int64) bool {
// Implement your logic here
return
}
func (m MySemaphore) Release(param1 int64) {
// Implement your logic here
return
}
func (m MySemaphore) Current() int64 {
// Implement your logic here
return
}
type Semaphore interface {
Acquire(ctx context.Context, n int64) error
TryAcquire(n int64) bool
Release(n int64)
Current() int64
}func NewWeighted(capacity int64, opts ...Option) Semaphore// Create a new SemaphoreError
semaphoreerror := SemaphoreError{
Op: "example",
Name: "example",
Err: error{},
}type SemaphoreError struct {
Op string
Name string
Err error
}func (*SemaphoreError) Error() stringfunc (*SemaphoreError) Unwrap() errorfunc NewAcquireTimeoutError(semaphoreName string) error// Example usage of NewAcquireTimeoutError
result := NewAcquireTimeoutError(/* parameters */)func NewWeightExceedsCapacityError(semaphoreName string, weight, capacity int64) error// Example usage of NewWeightExceedsCapacityError
result := NewWeightExceedsCapacityError(/* parameters */)var ErrInvalidWeight = errors.New("ion: invalid weight, must be positive") // ErrInvalidWeight is returned when a negative or zero weight is provided to semaphore operations
// Example usage of Fairness
var value Fairness
// Initialize with appropriate valuetype Fairness intfunc (Fairness) String() string// Example usage of Option
var value Option
// Initialize with appropriate valuetype Option func(*config)func WithAcquireTimeout(timeout time.Duration) Optionfunc WithFairness(fairness Fairness) Optionfunc WithLogger(logger observe.Logger) Optionfunc WithMetrics(metrics observe.Metrics) Optionfunc WithName(name string) Optionfunc WithTracer(tracer observe.Tracer) Option// Example implementation of Semaphore
type MySemaphore struct {
// Add your fields here
}
func (m MySemaphore) Acquire(param1 context.Context, param2 int64) error {
// Implement your logic here
return
}
func (m MySemaphore) TryAcquire(param1 int64) bool {
// Implement your logic here
return
}
func (m MySemaphore) Release(param1 int64) {
// Implement your logic here
return
}
func (m MySemaphore) Current() int64 {
// Implement your logic here
return
}
type Semaphore interface {
Acquire(ctx context.Context, n int64) error
TryAcquire(n int64) bool
Release(n int64)
Current() int64
}func NewWeighted(capacity int64, opts ...Option) Semaphore// Create a new SemaphoreError
semaphoreerror := SemaphoreError{
Op: "example",
Name: "example",
Err: error{},
}type SemaphoreError struct {
Op string
Name string
Err error
}func (*SemaphoreError) Error() stringfunc (*SemaphoreError) Unwrap() errorfunc NewAcquireTimeoutError(semaphoreName string) error// Example usage of NewAcquireTimeoutError
result := NewAcquireTimeoutError(/* parameters */)func NewWeightExceedsCapacityError(semaphoreName string, weight, capacity int64) error// Example usage of NewWeightExceedsCapacityError
result := NewWeightExceedsCapacityError(/* parameters */)