mirror of
https://github.com/danog/asyncConstruct.git
synced 2024-12-02 09:17:48 +01:00
34 lines
728 B
PHP
34 lines
728 B
PHP
<?php
|
|
|
|
use Amp\Loop;
|
|
use danog\BlockingConstruct;
|
|
|
|
use function Amp\delay;
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
class BlockingTest
|
|
{
|
|
use BlockingConstruct;
|
|
/**
|
|
* Async constructor function.
|
|
*
|
|
* Typically, one would establish an async AMP database connection here, or do some other async stuff.
|
|
*
|
|
* @param integer $delay Constructor delay
|
|
*
|
|
* @return \Generator
|
|
*/
|
|
protected function __construct_async(int $delay): \Generator
|
|
{
|
|
yield delay($delay);
|
|
echo "Inited after $delay milliseconds!".PHP_EOL;
|
|
}
|
|
}
|
|
|
|
Loop::run(function () {
|
|
echo "Before starting constructor".PHP_EOL;
|
|
$test = new BlockingTest(1000);
|
|
echo "Started constructor!".PHP_EOL;
|
|
});
|