1
0
mirror of https://github.com/danog/amp.git synced 2025-01-23 05:41:25 +01:00
amp/lib/Subscriber.php

52 lines
998 B
PHP
Raw Normal View History

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
*/
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
*/
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
* @param callable $unsubscribe
2016-05-27 15:44:01 -05:00
*/
public function __construct($id, Awaitable $awaitable, callable $unsubscribe) {
2016-05-29 11:35:09 -05:00
$this->id = $id;
$this->awaitable = $awaitable;
$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}
*/
public function unsubscribe() {
$unsubscribe = $this->unsubscribe;
$unsubscribe($this->id);
2016-05-27 15:44:01 -05:00
}
}