mirror of
https://github.com/danog/amp.git
synced 2025-01-23 05:41:25 +01:00
52 lines
992 B
PHP
52 lines
992 B
PHP
<?php
|
|
|
|
namespace Amp;
|
|
|
|
use Interop\Async\Awaitable;
|
|
|
|
/**
|
|
* Subscriber implementation returned from implementors of \Amp\Observable.
|
|
*/
|
|
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);
|
|
}
|
|
}
|