trait HasWaiterTrait

Contains reusable functionality for resources that have long operations which require waiting in order to reach a particular state.

Methods

waitUntil (string $status, int $timeout = 60, int $sleepPeriod = 1)

Provides a blocking operation until the resource has reached a particular state. The method will enter a loop, requesting feedback from the remote API until it sends back an appropriate status.

waitWithCallback (callable $fn, int|bool $timeout = 60, int $sleepPeriod = 1)

Provides a blocking operation until the resource has reached a particular state. The method will enter a loop, executing the callback until TRUE is returned. This provides great flexibility.

waitUntilActive (int|bool $timeout = false)

Convenience method providing a blocking operation until the resource transitions to an ACTIVE status.

waitUntilDeleted ($timeout = 60, int $sleepPeriod = 1)

No description

Details

waitUntil(string $status, int $timeout = 60, int $sleepPeriod = 1)

Provides a blocking operation until the resource has reached a particular state. The method will enter a loop, requesting feedback from the remote API until it sends back an appropriate status.

Parameters

$status string The state to be reached
$timeout int The maximum timeout. If the total time taken by the waiter has reached or exceed this timeout, the blocking operation will immediately cease.
$sleepPeriod int The amount of time to pause between each HTTP request.

Example code

$hasWaiterTrait->waitUntil($status, $timeout, $sleepPeriod);

waitWithCallback(callable $fn, int|bool $timeout = 60, int $sleepPeriod = 1)

Provides a blocking operation until the resource has reached a particular state. The method will enter a loop, executing the callback until TRUE is returned. This provides great flexibility.

Parameters

$fn callable An anonymous function that will be executed on every iteration. You can encapsulate your own logic to determine whether the resource has successfully transitioned. When TRUE is returned by the callback, the loop will end.
$timeout int|bool The maximum timeout in seconds. If the total time taken by the waiter has reached or exceed this timeout, the blocking operation will immediately cease. If FALSE is provided, the timeout will never be considered.
$sleepPeriod int The amount of time to pause between each HTTP request.

Example code

$hasWaiterTrait->waitWithCallback($fn, $timeout, $sleepPeriod);

waitUntilActive(int|bool $timeout = false)

Convenience method providing a blocking operation until the resource transitions to an ACTIVE status.

Parameters

$timeout int|bool The maximum timeout in seconds. If the total time taken by the waiter has reached or exceed this timeout, the blocking operation will immediately cease. If FALSE is provided, the timeout will never be considered.

Example code

$hasWaiterTrait->waitUntilActive($timeout);

waitUntilDeleted($timeout = 60, int $sleepPeriod = 1)

Parameters

$timeout
$sleepPeriod int

Example code

$hasWaiterTrait->waitUntilDeleted($timeout, $sleepPeriod);