diff --git a/.gitignore b/.gitignore index d1502b0..e9c8bd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ composer.lock +.vscode \ No newline at end of file diff --git a/promises/index.php b/promises/index.php index 7866911..ee70ae9 100644 --- a/promises/index.php +++ b/promises/index.php @@ -9,10 +9,7 @@ Lib\plain(); Lib\printf('https://sergio.am/code/www-tests'); use GuzzleHttp\Client; -use GuzzleHttp\Promise; use GuzzleHttp\Pool; -use GuzzleHttp\Psr7\Response; -use GuzzleHttp\Promise\EachPromise; Lib\printf('client'); diff --git a/promises/simple.php b/promises/simple.php new file mode 100644 index 0000000..08efc16 --- /dev/null +++ b/promises/simple.php @@ -0,0 +1,37 @@ + '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');