1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-12 09:09:35 +01:00
parallel/test/Worker/Fixtures/TestTask.php

29 lines
575 B
PHP
Raw Normal View History

2016-12-30 02:16:04 +01:00
<?php
2015-08-29 03:55:30 +02:00
namespace Amp\Parallel\Test\Worker\Fixtures;
2016-08-18 18:04:48 +02:00
2017-12-06 01:37:33 +01:00
use Amp\Delayed;
2017-05-18 09:51:31 +02:00
use Amp\Parallel\Worker\Environment;
use Amp\Parallel\Worker\Task;
2015-08-29 03:55:30 +02:00
2018-10-07 16:50:45 +02:00
class TestTask implements Task
{
2015-08-29 03:55:30 +02:00
private $returnValue;
2017-12-06 01:37:33 +01:00
private $delay = 0;
2015-08-29 03:55:30 +02:00
2018-10-07 16:50:45 +02:00
public function __construct($returnValue, int $delay = 0)
{
2015-08-29 03:55:30 +02:00
$this->returnValue = $returnValue;
2017-12-06 01:37:33 +01:00
$this->delay = $delay;
2015-08-29 03:55:30 +02:00
}
2018-10-07 16:50:45 +02:00
public function run(Environment $environment)
{
2017-12-06 01:37:33 +01:00
if ($this->delay) {
return new Delayed($this->delay, $this->returnValue);
}
2016-01-25 06:04:29 +01:00
return $this->returnValue;
2015-08-29 03:55:30 +02:00
}
}