Documentation

CurlPromise
in package
implements Promise

Promise represents a response that may not be available yet, but will be resolved at some point in future. It acts like a proxy to the actual response.

This interface is an extension of the promises/a+ specification https://promisesaplus.com/ Value is replaced by an object where its class implement a Psr\Http\Message\RequestInterface. Reason is replaced by an object where its class implement a Http\Client\Exception.

Tags
license

http://opensource.org/licenses/MIT MIT

author

Михаил Красильников m.krasilnikov@yandex.ru

Table of Contents

Interfaces

Promise
Promise represents a value that may not be available yet, but will be resolved at some point in future.

Properties

$core  : PromiseCore
Shared promise core.
$runner  : MultiRunner
Requests runner.

Methods

__construct()  : mixed
Create new promise.
getState()  : string
Get the state of the promise, one of PENDING, FULFILLED or REJECTED.
then()  : Promise
Add behavior for when the promise is resolved or rejected.
wait()  : ResponseInterface|null
Wait for the promise to be fulfilled or rejected.

Properties

Methods

getState()

Get the state of the promise, one of PENDING, FULFILLED or REJECTED.

public getState() : string
Return values
string

then()

Add behavior for when the promise is resolved or rejected.

public then([callable $onFulfilled = null ][, callable $onRejected = null ]) : Promise

If you do not care about one of the cases, you can set the corresponding callable to null The callback will be called when the response or exception arrived and never more than once.

Parameters
$onFulfilled : callable = null

Called when a response will be available

$onRejected : callable = null

Called when an error happens.

You must always return the Response in the interface or throw an Exception

Return values
Promise

Always returns a new promise which is resolved with value of the executed callback (onFulfilled / onRejected)

wait()

Wait for the promise to be fulfilled or rejected.

public wait([bool $unwrap = true ]) : ResponseInterface|null

When this method returns, the request has been resolved and the appropriate callable has terminated.

When called with the unwrap option

Parameters
$unwrap : bool = true

Whether to return resolved value / throw reason or not

Tags
throws
Exception

The rejection reason

Return values
ResponseInterface|null

Resolved value, null if $unwrap is set to false


        
On this page

Search results