Skip to content

Commit

Permalink
Allow sending synchronous api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Feb 21, 2017
1 parent 6244d99 commit 8c71aab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ public function postMessage(Message $message)
* @param string $method The API method to call.
* @param array $args An associative array of arguments to pass to the
* method call.
* @param bool $callDeferred Wether to call the API asynchronous or not.
*
* @return \React\Promise\PromiseInterface A promise for an API response.
*/
public function apiCall($method, array $args = [])
public function apiCall($method, array $args = [], $callDeferred = true)
{
// create the request url
$requestUrl = self::BASE_URL . $method;
Expand All @@ -393,9 +394,13 @@ public function apiCall($method, array $args = [])
]);

// Add requests to the event loop to be handled at a later date.
$this->loop->futureTick(function () use ($promise) {
if ($callDeferred) {
$this->loop->futureTick(function () use ($promise) {
$promise->wait();
});
} else {
$promise->wait();
});
}

// When the response has arrived, parse it and resolve. Note that our
// promises aren't pretty; Guzzle promises are not compatible with React
Expand Down

0 comments on commit 8c71aab

Please sign in to comment.