public function unsubscribe($name, $id = null, $callback = null)
{
$self = $this;
if (!is_string($name)) {
throw new TypeError('topic name must be a string');
}
if ($id === null && $callback === null) {
unset($this->topics[$name]);
return;
}
if (is_callable($id) && !is_callable($callback)) {
$callback = $id;
$id = null;
}
if ($id === null) {
if ($this->id === null) {
if (isset($this->topics[$name])) {
$topics = $this->topics[$name];
$ids = array_keys($topics);
foreach ($ids as $id) {
$this->delTopic($topics, $id, $callback);
}
}
} else {
$this->id->then(function ($id) use($self, $name, $callback) {
$self->unsubscribe($name, $id, $callback);
});
}
} elseif (isFuture($id)) {
$id->then(function ($id) use($self, $name, $callback) {
$self->unsubscribe($name, $id, $callback);
});
} else {
$this->delTopic($this->topics[$name], $id, $callback);
}
if (isset($this->topics[$name]) && count($this->topics[$name]) === 0) {
unset($this->topics[$name]);
}
}