Skip to content

Commit

Permalink
Return a promise from the listen method
Browse files Browse the repository at this point in the history
  • Loading branch information
PeeHaa committed Jan 4, 2017
1 parent 97b3ba2 commit 2bf5467
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/Client/GitAmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Amp\Artax\Client;
use Amp\Artax\ClientException;
use Amp\Artax\Request;
use Amp\Success;
use ekinhbayar\GitAmp\Events\Factory;
use ekinhbayar\GitAmp\Events\GithubEventType;
use ekinhbayar\GitAmp\Github\Credentials;
Expand Down Expand Up @@ -63,18 +64,17 @@ public function request(): Promise
}
}

/**
* @return \Generator
*/
public function listen(): \Generator
public function listen(): Promise
{
$response = yield $this->request();
return \Amp\resolve(function() {
$response = yield $this->request();

$results = new Results($this->githubEventType, $this->eventFactory);
$results = new Results($this->githubEventType, $this->eventFactory);

$results->appendResponse($response);
$results->appendResponse($response);

return $results;
return new Success($results);
});
}

private function getAuthHeader(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Websocket/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public function onOpen(int $clientId, $handshakeData) {

yield $this->counter->increment("connected_users");

$this->emit(yield from $this->gitamp->listen());
$this->emit(yield $this->gitamp->listen());

repeat(function() {
$this->emit(yield from $this->gitamp->listen());
$this->emit(yield $this->gitamp->listen());
}, 8000);

}
Expand Down

0 comments on commit 2bf5467

Please sign in to comment.