tsiura / promise-watcher
There is no license information available for the latest version (0.1) of this package.
A PHP library for asynchronous, promise-based object watching
0.1
2023-04-07 14:14 UTC
Requires
- php: ^8.2
- psr/log: ^3.0
- react/event-loop: ^1.3
- react/promise: ^2.9
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.9
README
A PHP library for asynchronous, promise-based object watching.
basic usage example
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);