Browse Source

simple promise (xdebug things)

master
Sergio Álvarez 2 years ago
parent
commit
9be9f6f096
  1. 1
      .gitignore
  2. 3
      promises/index.php
  3. 37
      promises/simple.php

1
.gitignore

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

3
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');

37
promises/simple.php

@ -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');
Loading…
Cancel
Save