class ConcurrencyLimiterBuilder

Traits

Properties

int $maxLocks

The maximum number of entities that can hold the lock at the same time.

int $releaseAfter

The number of seconds to maintain the lock until it is automatically released.

int $timeout

The amount of time to block until a lock is available.

int $sleep

The number of milliseconds to wait between attempts to acquire the lock.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

__construct(RedisProxy $connection, string $name)

Create a new builder instance.

limit(int $maxLocks)

Set the maximum number of locks that can be obtained per time window.

releaseAfter(DateTimeInterface|DateInterval|int $releaseAfter)

Set the number of seconds until the lock will be released.

block(int $timeout)

Set the amount of time to block until a lock is available.

sleep(int $sleep)

Set the number of milliseconds to wait between lock acquisition attempts.

acquire()

Acquire a lease on one of the limiter's slots, waiting up to the configured timeout.

mixed
then(callable $callback, callable|null $failure = null)

Execute the given callback if a lock is obtained, otherwise call the failure callback.

createLimiter()

Create the concurrency limiter instance.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

at line 44
__construct(RedisProxy $connection, string $name)

Create a new builder instance.

Parameters

RedisProxy $connection

the Redis connection instance

string $name

the name of the lock

at line 53
ConcurrencyLimiterBuilder limit(int $maxLocks)

Set the maximum number of locks that can be obtained per time window.

Parameters

int $maxLocks

Return Value

ConcurrencyLimiterBuilder

at line 63
ConcurrencyLimiterBuilder releaseAfter(DateTimeInterface|DateInterval|int $releaseAfter)

Set the number of seconds until the lock will be released.

Parameters

DateTimeInterface|DateInterval|int $releaseAfter

Return Value

ConcurrencyLimiterBuilder

at line 73
ConcurrencyLimiterBuilder block(int $timeout)

Set the amount of time to block until a lock is available.

Parameters

int $timeout

Return Value

ConcurrencyLimiterBuilder

at line 83
ConcurrencyLimiterBuilder sleep(int $sleep)

Set the number of milliseconds to wait between lock acquisition attempts.

Parameters

int $sleep

Return Value

ConcurrencyLimiterBuilder

at line 95
ConcurrencyLease acquire()

Acquire a lease on one of the limiter's slots, waiting up to the configured timeout.

Return Value

ConcurrencyLease

Exceptions

LimiterTimeoutException

at line 105
mixed then(callable $callback, callable|null $failure = null)

Execute the given callback if a lock is obtained, otherwise call the failure callback.

Parameters

callable $callback
callable|null $failure

Return Value

mixed

Exceptions

LimiterTimeoutException

at line 143
protected ConcurrencyLimiter createLimiter()

Create the concurrency limiter instance.

Return Value

ConcurrencyLimiter