PHP7 Pool

This commit is contained in:
Dominik Liebler
2016-09-22 14:16:12 +02:00
parent 7beb1420b4
commit 61a6f03f04
5 changed files with 58 additions and 98 deletions

View File

@@ -2,18 +2,20 @@
namespace DesignPatterns\Creational\Pool;
class Worker
class StringReverseWorker
{
/**
* @var \DateTime
*/
private $createdAt;
public function __construct()
{
// let's say that constuctor does really expensive work...
// for example creates "thread"
$this->createdAt = new \DateTime();
}
public function run($image, array $callback)
public function run(string $text)
{
// do something with $image...
// and when it's done, execute callback
call_user_func($callback, $this);
return strrev($text);
}
}