simple promise (xdebug things)

This commit is contained in:
Sergio Álvarez 2019-11-23 14:17:04 +01:00
parent 522b690885
commit 9be9f6f096
3 changed files with 38 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
vendor/ vendor/
composer.lock composer.lock
.vscode

View File

@ -9,10 +9,7 @@ Lib\plain();
Lib\printf('https://sergio.am/code/www-tests'); Lib\printf('https://sergio.am/code/www-tests');
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Promise;
use GuzzleHttp\Pool; use GuzzleHttp\Pool;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Promise\EachPromise;
Lib\printf('client'); Lib\printf('client');

37
promises/simple.php Normal file
View File

@ -0,0 +1,37 @@
<?php
require_once(dirname(__FILE__) .'/vendor/autoload.php');
// lib.php, helper functions
Lib\plain();
Lib\printf('https://sergio.am/code/www-tests');
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
Lib\printf('client');
$client = new Client(['base_uri' => 'http://httpbin.org/']);
Lib\printf('promise');
$promise = $client->getAsync('/get');
Lib\printf('then');
$promise->then(
function (ResponseInterface $res) {
echo $res->getStatusCode() . "\n";
},
function (RequestException $e) {
echo $e->getMessage() . "\n";
echo $e->getRequest()->getMethod();
}
);
Lib\printf('wait');
$promise->wait();
Lib\printf('end');