WaitConditionLoop
Wait loop that reaches a condition or times out
Loading...
Searching...
No Matches
Wikimedia\WaitConditionLoop Class Reference

Wait loop that reaches a condition or times out. More...

Public Member Functions

 __construct (callable $condition, $timeout=5.0, &$busyCallbacks=[])
 
 invoke ()
 Invoke the loop and continue until either:
 
 getLastWaitTime ()
 

Public Attributes

const CONDITION_REACHED = 1
 
const CONDITION_CONTINUE = 0
 
const CONDITION_FAILED = -1
 
const CONDITION_TIMED_OUT = -2
 
const CONDITION_ABORTED = -3
 

Protected Member Functions

 usleep ( $microseconds)
 
 getWallTime ()
 
 getCpuTime ()
 

Detailed Description

Wait loop that reaches a condition or times out.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\WaitConditionLoop::__construct ( callable $condition,
$timeout = 5.0,
& $busyCallbacks = [] )
Parameters
callable$conditionCallback that returns a WaitConditionLoop::CONDITION_ constant
float$timeoutTimeout in seconds
array&$busyCallbacksList of callbacks to do useful work (by reference)

Member Function Documentation

◆ getCpuTime()

Wikimedia\WaitConditionLoop::getCpuTime ( )
protected
Returns
float Returns 0.0 if not supported (Windows on PHP < 7) @codeCoverageIgnore

◆ getLastWaitTime()

Wikimedia\WaitConditionLoop::getLastWaitTime ( )
Returns
float Seconds

◆ getWallTime()

Wikimedia\WaitConditionLoop::getWallTime ( )
protected
Returns
float @codeCoverageIgnore

◆ invoke()

Wikimedia\WaitConditionLoop::invoke ( )

Invoke the loop and continue until either:

  • a) The condition callback returns neither CONDITION_CONTINUE nor false
  • b) The timeout is reached Thus a condition callback can return true (stop) or false (continue) for convenience. In such cases, the halting result of "true" will be converted to CONDITION_REACHED.

If $timeout is 0, then only the condition callback will be called (no busy callbacks), and this will immediately return CONDITION_FAILED if the condition was not met.

Exceptions in callbacks will be caught and the callback will be swapped with one that simply rethrows that exception back to the caller when invoked.

Returns
int WaitConditionLoop::CONDITION_* constant
Exceptions

Exception Any error from the condition callback

◆ usleep()

Wikimedia\WaitConditionLoop::usleep ( $microseconds)
protected
Parameters
int$microseconds@codeCoverageIgnore

The documentation for this class was generated from the following file: