SyncPromise
in package
Synchronous promise implementation following Promises A+ spec.
Uses a hybrid approach for optimal memory and performance:
- Lightweight closures in queue (fast execution)
- Heavy payload (callbacks) stored on promise objects and cleared after use
Library users should use @see \Automattic\WooCommerce\Vendor\GraphQL\Deferred to create promises.
Tags
Table of Contents
- FULFILLED = 1
- PENDING = 0
- REJECTED = 2
- $result : mixed
- Resolved value or rejection reason.
- $state : int
- Current promise state.
- $waiting : array<string|int, mixed>
- Promises created in `then` method awaiting resolution.
- getQueue() : SplQueue<string|int, callable>
- TODO remove in next major version.
- reject() : $this
- resolve() : self
- runQueue() : void
- TODO remove in next major version.
- then() : self
- enqueueWaitingPromises() : void
Constants
FULFILLED
public
mixed
FULFILLED
= 1
PENDING
public
mixed
PENDING
= ""
REJECTED
public
mixed
REJECTED
= 2
Properties
$result
Resolved value or rejection reason.
public
mixed
$result
$state
Current promise state.
public
int
$state
= self::PENDING
$waiting
Promises created in `then` method awaiting resolution.
protected
array<string|int, mixed>
$waiting
= []
Methods
getQueue()
TODO remove in next major version.
public
static getQueue() : SplQueue<string|int, callable>
Tags
Return values
SplQueue<string|int, callable> —reject()
public
reject(Throwable $reason) : $this
Parameters
- $reason : Throwable
Tags
Return values
$this —resolve()
public
resolve(mixed $value) : self
Parameters
- $value : mixed
Tags
Return values
self —runQueue()
TODO remove in next major version.
public
static runQueue() : void
Tags
Return values
void —then()
public
then([callable|null $onFulfilled = null ][, callable|null $onRejected = null ]) : self
Parameters
- $onFulfilled : callable|null = null
- $onRejected : callable|null = null
Tags
Return values
self —enqueueWaitingPromises()
private
enqueueWaitingPromises() : void
