guards

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockCountPrefix = "lock-count"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LockCounter

type LockCounter struct {
	TryMax     int           // 最大回数
	Expiration time.Duration // 判定対象期間
	Trigger    Trigger
	// contains filtered or unexported fields
}

func TimedCounter

func TimedCounter(key string, max int, expiration time.Duration, trigger Trigger) *LockCounter

func (*LockCounter) Clear

func (c *LockCounter) Clear(ctx context.Context)

func (*LockCounter) Fire

func (c *LockCounter) Fire(ctx context.Context, f func()) (bool, error)

func (*LockCounter) Increment

func (c *LockCounter) Increment(ctx context.Context) (bool, error)

func (*LockCounter) Key

func (c *LockCounter) Key() string

type LockTrigger

type LockTrigger struct {
	Lock locks.Lock
}

func (*LockTrigger) Fire

func (t *LockTrigger) Fire(ctx context.Context) error

func (*LockTrigger) Fired

func (t *LockTrigger) Fired(ctx context.Context) (bool, error)

func (*LockTrigger) Reset

func (t *LockTrigger) Reset(ctx context.Context)

type Trigger

type Trigger interface {
	Fire(ctx context.Context) error          // 発火
	Fired(ctx context.Context) (bool, error) // 発火済み
	Reset(ctx context.Context)
}

Jump to

Keyboard shortcuts

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