resource

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package resource defines different concurrent access strategies for resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounded

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

Bounded is a bounded resource.

func NewBounded

func NewBounded(n int) *Bounded

NewBounded creates a new bounded resource that can be acquired n times concurrently.

func (*Bounded) Acquire

func (r *Bounded) Acquire(ctx context.Context) bool

Acquire acquires the resource. If the resource is already acquired n times, wait until another one is released.

func (*Bounded) Release

func (r *Bounded) Release()

Release a previously acquired resource.

type R

type R interface {
	Acquire(ctx context.Context) bool
	Release()
}

R is the resource interface.

type Throttled

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

Throttled in a rate-limited resource.

func NewThrottled

func NewThrottled(requestsPerSecond int64) *Throttled

NewThrottled creates a resource with the given rate limit.

func (*Throttled) Acquire

func (r *Throttled) Acquire(ctx context.Context) bool

Acquire can be called concurrently, and blocks callers so that are let through as the rate limit requires.

func (*Throttled) Release

func (*Throttled) Release()

Release for this resource type is no-op.

Jump to

Keyboard shortcuts

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