Promise example

/** * @param array<mixed> $options */
    public function __invoke(RequestInterface $request, array $options): PromiseInterface
    {
        if ($this->inner->count() > 0) {
            return \call_user_func($this->inner, $request$options);
        }

        if ($this->isRegistration($request)) {
            $this->registrationRequest = $request;
            $promise = new Promise();
            $promise->resolve(new Response(200, []$this->buildAppResponse($request)));

            return $promise;
        }

        if ($this->isRegistrationConfirmation($request)) {
            $this->confirmationRequest = $request;
            $promise = new Promise();
            $promise->resolve(new Response(200));

            return $promise;
        }
namespace Symfony\Component\HttpClient\Tests\Response;

use GuzzleHttp\Promise\Promise;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\Response\HttplugPromise;

class HttplugPromiseTest extends TestCase
{
    public function testComplexNesting()
    {
        $mkPromise = function D$result): HttplugPromise {
            $guzzlePromise = new Promise(function D) use (&$guzzlePromise$result) {
                $guzzlePromise->resolve($result);
            });

            return new HttplugPromise($guzzlePromise);
        };

        $promise1 = $mkPromise('result');
        $promise2 = $promise1->then($mkPromise);
        $promise3 = $promise2->then(fn ($result) => $result);

        $this->assertSame('result', $promise3->wait());
    }
Home | Imprint | This part of the site doesn't use cookies.