2016-05-27 15:44:01 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp;
|
|
|
|
|
|
|
|
use Interop\Async\Awaitable;
|
|
|
|
|
2016-06-01 11:37:12 -05:00
|
|
|
/**
|
2016-06-02 17:11:25 -05:00
|
|
|
* Subscriber implementation returned from implementors of \Amp\Observable.
|
2016-06-01 11:37:12 -05:00
|
|
|
*/
|
2016-06-02 10:35:41 -05:00
|
|
|
final class Subscriber implements Awaitable {
|
2016-05-27 15:44:01 -05:00
|
|
|
/**
|
2016-05-29 11:35:09 -05:00
|
|
|
* @var string
|
2016-05-27 15:44:01 -05:00
|
|
|
*/
|
2016-05-29 11:35:09 -05:00
|
|
|
private $id;
|
2016-05-27 15:44:01 -05:00
|
|
|
|
|
|
|
/**
|
2016-05-29 11:35:09 -05:00
|
|
|
* @var \Interop\Async\Awaitable
|
2016-05-27 15:44:01 -05:00
|
|
|
*/
|
2016-05-29 11:35:09 -05:00
|
|
|
private $awaitable;
|
2016-05-27 15:44:01 -05:00
|
|
|
|
|
|
|
/**
|
2016-05-29 11:35:09 -05:00
|
|
|
* @var callable
|
2016-05-27 15:44:01 -05:00
|
|
|
*/
|
2016-06-02 10:35:41 -05:00
|
|
|
private $unsubscribe;
|
2016-05-27 15:44:01 -05:00
|
|
|
|
|
|
|
/**
|
2016-05-29 11:35:09 -05:00
|
|
|
* @param string $id
|
|
|
|
* @param \Interop\Async\Awaitable $awaitable
|
2016-06-02 10:35:41 -05:00
|
|
|
* @param callable $unsubscribe
|
2016-05-27 15:44:01 -05:00
|
|
|
*/
|
2016-06-02 10:35:41 -05:00
|
|
|
public function __construct($id, Awaitable $awaitable, callable $unsubscribe) {
|
2016-05-29 11:35:09 -05:00
|
|
|
$this->id = $id;
|
|
|
|
$this->awaitable = $awaitable;
|
2016-06-02 10:35:41 -05:00
|
|
|
$this->unsubscribe = $unsubscribe;
|
2016-05-27 15:44:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function when(callable $onResolved) {
|
2016-05-29 11:35:09 -05:00
|
|
|
$this->awaitable->when($onResolved);
|
2016-05-27 15:44:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2016-06-02 10:35:41 -05:00
|
|
|
public function unsubscribe() {
|
|
|
|
$unsubscribe = $this->unsubscribe;
|
|
|
|
$unsubscribe($this->id);
|
2016-05-27 15:44:01 -05:00
|
|
|
}
|
|
|
|
}
|