1. Go to this page and download the library: Download rikta/timed-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/ */
rikta / timed-loop example snippets
use Rikta\TimedLoop\TimedLoop;
$loop = new TimedLoop(fn () => @file_get_contents('http://localhost:8080/health.php'));
$healthResult = $loop();
use Rikta\TimedLoop\TimedLoop;
class RemoteRepositoryAdapter {
public function getNextItem(Repository $repository, Options $options): ?object { /*...*/ }
public function hasNextItem(Repository $repository, Options $options): bool { /*...*/ }
}
$options = new Options(/*...*/);
$repository = new Repository(/*...*/);
$repositoryAdapter = new RemoteRepositoryAdapter;
// instead of an anonymous function you can also provide callables via array
// the first element is the object/class-string/'self', the second one the method
$loop = new TimedLoop([$repositoryAdapter, 'getNextItem']);
// by default it waits until something else than `false`
$loop->untilItReturnsSomethingElseThan(null);
// by default it retries it after 50000 microseconds (1/1_000_000 second)
$loop->retryingAfterMicroseconds(100_000);
// by default it throws an exception after 10 seconds
$loop->forMaximumSeconds(60);
// run the loop until the callable returns a non-null-value, and return said value
$nextItem = $loop($repository, $options);
// you can also use $loop->invoke($repository, $options) if you don't like invoking variables ;)
$nextItem = (new TimedLoop([$repositoryAdapter, 'getNextItem']))
->untilItReturnsSomethingElseThan(null)
->retryingAfterMicroseconds(100_000)
->forMaximumSeconds(60)
->invoke($repository, $options);
// loops until hasNextItem() returns true
TimedLoop::loop([$repositoryAdapter, 'hasNextItem'], $repository, $options);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.