PHP code example of wikimedia / wait-condition-loop

1. Go to this page and download the library: Download wikimedia/wait-condition-loop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wikimedia / wait-condition-loop example snippets


// Pre-compute some value that will be needed later
$result = null;
$workCallback = function () use ( &$result ) {
    $result = ( $result !== null ) ? $result : $this->doWork();

    return $result
}

$loop = new WaitConditionLoop(
    function () use ( ... ) {
        if ( ... ) {
            // Condition reached; stop loop
            return WaitConditionLoop::CONDITION_REACHED;
        }
        // Condition not reached; keep checking
        return WaitConditionLoop::CONDITION_CONTINUE;
    },
    3.0, // timeout in seconds
    [ $workCallback ]
);
$status = $loop->invoke(); // CONDITION_* constant

// Call $workCallback as needed later