Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 276 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Utils:: (9 methods):
  queue()
  task()
  inspect()
  inspectAll()
  unwrap()
  all()
  some()
  any()
  settle()


Class: Utils  - X-Ref

queue(TaskQueueInterface $assign = null)   X-Ref
Get the global task queue used for promise resolution.

This task queue MUST be run in an event loop in order for promises to be
settled asynchronously. It will be automatically run when synchronously
waiting on a promise.

<code>
while ($eventLoop->isRunning()) {
GuzzleHttp\Promise\Utils::queue()->run();
}
</code>

param: TaskQueueInterface $assign Optionally specify a new queue instance.
return: TaskQueueInterface

task(callable $task)   X-Ref
Adds a function to run in the task queue when it is next `run()` and
returns a promise that is fulfilled or rejected with the result.

param: callable $task Task function to run.
return: PromiseInterface

inspect(PromiseInterface $promise)   X-Ref
Synchronously waits on a promise to resolve and returns an inspection
state array.

Returns a state associative array containing a "state" key mapping to a
valid promise state. If the state of the promise is "fulfilled", the
array will contain a "value" key mapping to the fulfilled value of the
promise. If the promise is rejected, the array will contain a "reason"
key mapping to the rejection reason of the promise.

param: PromiseInterface $promise Promise or value.
return: array

inspectAll($promises)   X-Ref
Waits on all of the provided promises, but does not unwrap rejected
promises as thrown exception.

Returns an array of inspection state arrays.

param: PromiseInterface[] $promises Traversable of promises to wait upon.
return: array

unwrap($promises)   X-Ref
Waits on all of the provided promises and returns the fulfilled values.

Returns an array that contains the value of each promise (in the same
order the promises were provided). An exception is thrown if any of the
promises are rejected.

param: iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
return: array

all($promises, $recursive = false)   X-Ref
Given an array of promises, return a promise that is fulfilled when all
the items in the array are fulfilled.

The promise's fulfillment value is an array with fulfillment values at
respective positions to the original array. If any promise in the array
rejects, the returned promise is rejected with the rejection reason.

param: mixed $promises  Promises or values.
param: bool  $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
return: PromiseInterface

some($count, $promises)   X-Ref
No description

any($promises)   X-Ref
No description

settle($promises)   X-Ref
Returns a promise that is fulfilled when all of the provided promises have
been fulfilled or rejected.

The returned promise is fulfilled with an array of inspection state arrays.

param: mixed $promises Promises or values.
return: PromiseInterface