PHP code example of tsiura / promise-watcher
1. Go to this page and download the library: Download tsiura/promise-watcher 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/ */
tsiura / promise-watcher example snippets
class EvalObjNum implements EvaluatedObjectInterface
{
public function __construct(
private readonly int $value,
) {
}
public function __toString(): string
{
return sprintf('%s', $this->value);
}
public function evaluate(mixed $object): bool
{
return (is_numeric($object) && $object == $this->value);
}
}
$watcher = new ObjectWatcher(Loop::get());
$w1 = $watcher->createWatching(new EvalObjNum(10), 1);
$w1->start()
->then(function ($value) {
echo sprintf('Evaluated successfully with value ' . $value) . PHP_EOL;
}, function (\Throwable $e) { echo $e->getMessage() . PHP_EOL; });
$watcher->evaluate(11);