1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Subscriber.php
2016-06-02 17:11:25 -05:00

52 lines
998 B
PHP

<?php
namespace Amp;
use Interop\Async\Awaitable;
/**
* Subscriber implementation returned from implementors of \Amp\Observable.
*/
final class Subscriber implements Awaitable {
/**
* @var string
*/
private $id;
/**
* @var \Interop\Async\Awaitable
*/
private $awaitable;
/**
* @var callable
*/
private $unsubscribe;
/**
* @param string $id
* @param \Interop\Async\Awaitable $awaitable
* @param callable $unsubscribe
*/
public function __construct($id, Awaitable $awaitable, callable $unsubscribe) {
$this->id = $id;
$this->awaitable = $awaitable;
$this->unsubscribe = $unsubscribe;
}
/**
* {@inheritdoc}
*/
public function when(callable $onResolved) {
$this->awaitable->when($onResolved);
}
/**
* {@inheritdoc}
*/
public function unsubscribe() {
$unsubscribe = $this->unsubscribe;
$unsubscribe($this->id);
}
}