2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
2016-08-16 23:39:25 +02:00
|
|
|
|
2015-07-21 04:24:51 +02:00
|
|
|
namespace Amp\Test;
|
|
|
|
|
2017-04-28 14:42:02 +02:00
|
|
|
use Amp\Delayed;
|
2020-09-28 05:19:52 +02:00
|
|
|
use Amp\PHPUnit\AsyncTestCase;
|
|
|
|
use function Amp\await;
|
2015-07-21 04:24:51 +02:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
class DelayedTest extends AsyncTestCase
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testDelayed(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-10-10 16:06:49 +02:00
|
|
|
$this->setMinimumRuntime(100);
|
|
|
|
|
2016-07-19 07:05:40 +02:00
|
|
|
$time = 100;
|
|
|
|
$value = "test";
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
$promise = new Delayed($time, $value);
|
2016-07-19 07:05:40 +02:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->assertSame($value, await($promise));
|
2015-07-21 04:28:51 +02:00
|
|
|
}
|
2017-01-08 08:15:57 +01:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testReference(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-10-10 16:06:49 +02:00
|
|
|
$this->setMinimumRuntime(100);
|
|
|
|
|
2017-01-08 08:15:57 +01:00
|
|
|
$time = 100;
|
|
|
|
$value = "test";
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
$promise = new Delayed($time, $value);
|
|
|
|
$promise->unreference();
|
|
|
|
$promise->reference();
|
2017-01-08 08:15:57 +01:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
await($promise);
|
2017-01-08 08:15:57 +01:00
|
|
|
}
|
2015-07-21 04:24:51 +02:00
|
|
|
}
|