/**
  * Emit URL shortening events
  *
  * @param string $url
  * @return \React\Promise\Deferred
  */
 public function emitShorteningEvents($url)
 {
     $host = Url::extractHost($url);
     list($privateDeferred, $userFacingPromise) = $this->preparePromises();
     $eventName = 'url.shorten.';
     if (count($this->emitter->listeners($eventName . $host)) > 0) {
         $eventName .= $host;
         $this->getLogger()->info('[Bigstock] emitting: ' . $eventName);
         $this->emitter->emit($eventName, [$url, $privateDeferred]);
     } elseif (count($this->emitter->listeners($eventName . 'all')) > 0) {
         $eventName .= 'all';
         $this->getLogger()->info('[Bigstock] emitting: ' . $eventName);
         $this->emitter->emit($eventName, [$url, $privateDeferred]);
     } else {
         $this->getLoop()->addTimer(0.1, function () use($privateDeferred) {
             $privateDeferred->reject();
         });
     }
     return $userFacingPromise;
 }
 /**
  * @param string $requestId
  * @param string $url
  *
  * @return \React\Promise\DeferredPromise
  */
 protected function emitShorteningEvents($requestId, $url)
 {
     $host = Url::extractHost($url);
     list($privateDeferred, $userFacingPromise) = $this->preparePromises();
     $eventName = 'url.shorten.';
     if (count($this->emitter->listeners($eventName . $host)) > 0) {
         $eventName .= $host;
         $this->logDebug('[' . $requestId . ']Emitting: ' . $eventName);
         $this->emitter->emit($eventName, [$url, $privateDeferred]);
     } elseif (count($this->emitter->listeners($eventName . 'all')) > 0) {
         $eventName .= 'all';
         $this->logDebug('[' . $requestId . ']Emitting: ' . $eventName);
         $this->emitter->emit($eventName, [$url, $privateDeferred]);
     } else {
         $this->loop->addTimer(0.1, function () use($privateDeferred) {
             $privateDeferred->reject();
         });
     }
     return $userFacingPromise;
 }