Update to Drupal 8.1.7. For more information, see https://www.drupal.org/project/drupal/releases/8.1.7

This commit is contained in:
Pantheon Automation 2016-07-18 09:07:48 -07:00 committed by Greg Anderson
parent 38ba7c357d
commit e9f047ccf8
61 changed files with 1613 additions and 561 deletions

View file

@ -1,5 +1,21 @@
# CHANGELOG
## 1.2.0 - 2016-05-18
* Update to now catch `\Throwable` on PHP 7+
## 1.1.0 - 2016-03-07
* Update EachPromise to prevent recurring on a iterator when advancing, as this
could trigger fatal generator errors.
* Update Promise to allow recursive waiting without unwrapping exceptions.
## 1.0.3 - 2015-10-15
* Update EachPromise to immediately resolve when the underlying promise iterator
is empty. Previously, such a promise would throw an exception when its `wait`
function was called.
## 1.0.2 - 2015-05-15
* Conditionally require functions.php.

View file

@ -208,7 +208,7 @@ of the promise is called.
```php
$promise = new Promise(function () use (&$promise) {
$promise->deliver('foo');
$promise->resolve('foo');
});
// Calling wait will return the value of the promise.
@ -227,11 +227,11 @@ $promise->wait(); // throws the exception.
```
Calling `wait` on a promise that has been fulfilled will not trigger the wait
function. It will simply return the previously delivered value.
function. It will simply return the previously resolved value.
```php
$promise = new Promise(function () { die('this is not called!'); });
$promise->deliver('foo');
$promise->resolve('foo');
echo $promise->wait(); // outputs "foo"
```
@ -268,7 +268,7 @@ $promise->reject('foo');
$promise->wait(false);
```
When unwrapping a promise, the delivered value of the promise will be waited
When unwrapping a promise, the resolved value of the promise will be waited
upon until the unwrapped value is not a promise. This means that if you resolve
promise A with a promise B and unwrap promise A, the value returned by the
wait function will be the value delivered to promise B.
@ -496,6 +496,6 @@ deferred, it is a small price to pay for keeping the stack size constant.
$promise = new Promise();
$promise->then(function ($value) { echo $value; });
// The promise is the deferred value, so you can deliver a value to it.
$promise->deliver('foo');
$promise->resolve('foo');
// prints "foo"
```

View file

@ -24,6 +24,9 @@ class EachPromise implements PromisorInterface
/** @var Promise */
private $aggregate;
/** @var bool */
private $mutex;
/**
* Configuration hash can include the following key value pairs:
*
@ -72,6 +75,8 @@ class EachPromise implements PromisorInterface
$this->createPromise();
$this->iterable->rewind();
$this->refillPending();
} catch (\Throwable $e) {
$this->aggregate->reject($e);
} catch (\Exception $e) {
$this->aggregate->reject($e);
}
@ -81,8 +86,14 @@ class EachPromise implements PromisorInterface
private function createPromise()
{
$this->mutex = false;
$this->aggregate = new Promise(function () {
reset($this->pending);
if (empty($this->pending) && !$this->iterable->valid()) {
$this->aggregate->resolve(null);
return;
}
// Consume a potentially fluctuating list of promises while
// ensuring that indexes are maintained (precluding array_shift).
while ($promise = current($this->pending)) {
@ -164,11 +175,25 @@ class EachPromise implements PromisorInterface
private function advanceIterator()
{
// Place a lock on the iterator so that we ensure to not recurse,
// preventing fatal generator errors.
if ($this->mutex) {
return false;
}
$this->mutex = true;
try {
$this->iterable->next();
$this->mutex = false;
return true;
} catch (\Throwable $e) {
$this->aggregate->reject($e);
$this->mutex = false;
return false;
} catch (\Exception $e) {
$this->aggregate->reject($e);
$this->mutex = false;
return false;
}
}
@ -181,9 +206,11 @@ class EachPromise implements PromisorInterface
}
unset($this->pending[$idx]);
$this->advanceIterator();
if (!$this->checkIfFinished()) {
// Only refill pending promises if we are not locked, preventing the
// EachPromise to recursively invoke the provided iterator, which
// cause a fatal error: "Cannot resume an already running generator"
if ($this->advanceIterator() && !$this->checkIfFinished()) {
// Add more pending promises if possible.
$this->refillPending();
}

View file

@ -37,6 +37,8 @@ class FulfilledPromise implements PromiseInterface
if ($p->getState() === self::PENDING) {
try {
$p->resolve($onFulfilled($value));
} catch (\Throwable $e) {
$p->reject($e);
} catch (\Exception $e) {
$p->reject($e);
}

View file

@ -61,17 +61,19 @@ class Promise implements PromiseInterface
{
$this->waitIfPending();
if (!$unwrap) {
return null;
}
$inner = $this->result instanceof PromiseInterface
? $this->result->wait($unwrap)
: $this->result;
if ($this->result instanceof PromiseInterface) {
return $this->result->wait($unwrap);
} elseif ($this->state === self::FULFILLED) {
return $this->result;
} else {
// It's rejected so "unwrap" and throw an exception.
throw exception_for($this->result);
if ($unwrap) {
if ($this->result instanceof PromiseInterface
|| $this->state === self::FULFILLED
) {
return $inner;
} else {
// It's rejected so "unwrap" and throw an exception.
throw exception_for($inner);
}
}
}
@ -93,6 +95,8 @@ class Promise implements PromiseInterface
$this->cancelFn = null;
try {
$fn();
} catch (\Throwable $e) {
$this->reject($e);
} catch (\Exception $e) {
$this->reject($e);
}
@ -204,6 +208,8 @@ class Promise implements PromiseInterface
// Forward rejections down the chain.
$promise->reject($value);
}
} catch (\Throwable $reason) {
$promise->reject($reason);
} catch (\Exception $reason) {
$promise->reject($reason);
}
@ -257,11 +263,10 @@ class Promise implements PromiseInterface
$this->waitList = null;
foreach ($waitList as $result) {
descend:
$result->waitIfPending();
if ($result->result instanceof Promise) {
while ($result->result instanceof Promise) {
$result = $result->result;
goto descend;
$result->waitIfPending();
}
}
}

View file

@ -38,6 +38,9 @@ class RejectedPromise implements PromiseInterface
try {
// Return a resolved promise if onRejected does not throw.
$p->resolve($onRejected($reason));
} catch (\Throwable $e) {
// onRejected threw, so return a rejected promise.
$p->reject($e);
} catch (\Exception $e) {
// onRejected threw, so return a rejected promise.
$p->reject($e);

View file

@ -56,6 +56,7 @@ class TaskQueue
*/
public function run()
{
/** @var callable $task */
while ($task = array_shift($this->queue)) {
$task();
}

View file

@ -42,6 +42,8 @@ function task(callable $task)
$queue->add(function () use ($task, $promise) {
try {
$promise->resolve($task());
} catch (\Throwable $e) {
$promise->reject($e);
} catch (\Exception $e) {
$promise->reject($e);
}
@ -97,11 +99,11 @@ function rejection_for($reason)
*
* @param mixed $reason
*
* @return \Exception
* @return \Exception|\Throwable
*/
function exception_for($reason)
{
return $reason instanceof \Exception
return $reason instanceof \Exception || $reason instanceof \Throwable
? $reason
: new RejectionException($reason);
}
@ -146,9 +148,11 @@ function inspect(PromiseInterface $promise)
'value' => $promise->wait()
];
} catch (RejectionException $e) {
return ['state' => 'rejected', 'reason' => $e->getReason()];
return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()];
} catch (\Throwable $e) {
return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
} catch (\Exception $e) {
return ['state' => 'rejected', 'reason' => $e];
return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
}
}
@ -184,6 +188,7 @@ function inspect_all($promises)
*
* @return array
* @throws \Exception on error
* @throws \Throwable on error in PHP >=7
*/
function unwrap($promises)
{
@ -304,10 +309,10 @@ function settle($promises)
return each(
$promises,
function ($value, $idx) use (&$results) {
$results[$idx] = ['state' => 'fulfilled', 'value' => $value];
$results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value];
},
function ($reason, $idx) use (&$results) {
$results[$idx] = ['state' => 'rejected', 'reason' => $reason];
$results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason];
}
)->then(function () use (&$results) {
ksort($results);