Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -0,0 +1,151 @@
<?php
namespace GuzzleHttp\Promise;
use Exception;
use Generator;
use Throwable;
/**
* Creates a promise that is resolved using a generator that yields values or
* promises (somewhat similar to C#'s async keyword).
*
* When called, the coroutine function will start an instance of the generator
* and returns a promise that is fulfilled with its final yielded value.
*
* Control is returned back to the generator when the yielded promise settles.
* This can lead to less verbose code when doing lots of sequential async calls
* with minimal processing in between.
*
* use GuzzleHttp\Promise;
*
* function createPromise($value) {
* return new Promise\FulfilledPromise($value);
* }
*
* $promise = Promise\coroutine(function () {
* $value = (yield createPromise('a'));
* try {
* $value = (yield createPromise($value . 'b'));
* } catch (\Exception $e) {
* // The promise was rejected.
* }
* yield $value . 'c';
* });
*
* // Outputs "abc"
* $promise->then(function ($v) { echo $v; });
*
* @param callable $generatorFn Generator function to wrap into a promise.
*
* @return Promise
* @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
*/
final class Coroutine implements PromiseInterface
{
/**
* @var PromiseInterface|null
*/
private $currentPromise;
/**
* @var Generator
*/
private $generator;
/**
* @var Promise
*/
private $result;
public function __construct(callable $generatorFn)
{
$this->generator = $generatorFn();
$this->result = new Promise(function () {
while (isset($this->currentPromise)) {
$this->currentPromise->wait();
}
});
$this->nextCoroutine($this->generator->current());
}
public function then(
callable $onFulfilled = null,
callable $onRejected = null
) {
return $this->result->then($onFulfilled, $onRejected);
}
public function otherwise(callable $onRejected)
{
return $this->result->otherwise($onRejected);
}
public function wait($unwrap = true)
{
return $this->result->wait($unwrap);
}
public function getState()
{
return $this->result->getState();
}
public function resolve($value)
{
$this->result->resolve($value);
}
public function reject($reason)
{
$this->result->reject($reason);
}
public function cancel()
{
$this->currentPromise->cancel();
$this->result->cancel();
}
private function nextCoroutine($yielded)
{
$this->currentPromise = promise_for($yielded)
->then([$this, '_handleSuccess'], [$this, '_handleFailure']);
}
/**
* @internal
*/
public function _handleSuccess($value)
{
unset($this->currentPromise);
try {
$next = $this->generator->send($value);
if ($this->generator->valid()) {
$this->nextCoroutine($next);
} else {
$this->result->resolve($value);
}
} catch (Exception $exception) {
$this->result->reject($exception);
} catch (Throwable $throwable) {
$this->result->reject($throwable);
}
}
/**
* @internal
*/
public function _handleFailure($reason)
{
unset($this->currentPromise);
try {
$nextYield = $this->generator->throw(exception_for($reason));
// The throw was caught, so keep iterating on the coroutine
$this->nextCoroutine($nextYield);
} catch (Exception $exception) {
$this->result->reject($exception);
} catch (Throwable $throwable) {
$this->result->reject($throwable);
}
}
}

View File

@@ -263,10 +263,17 @@ class Promise implements PromiseInterface
$this->waitList = null;
foreach ($waitList as $result) {
$result->waitIfPending();
while ($result->result instanceof Promise) {
$result = $result->result;
while (true) {
$result->waitIfPending();
if ($result->result instanceof Promise) {
$result = $result->result;
} else {
if ($result->result instanceof PromiseInterface) {
$result->result->wait(false);
}
break;
}
}
}
}

View File

@@ -10,7 +10,7 @@ namespace GuzzleHttp\Promise;
*
* GuzzleHttp\Promise\queue()->run();
*/
class TaskQueue
class TaskQueue implements TaskQueueInterface
{
private $enableShutdown = true;
private $queue = [];
@@ -30,30 +30,16 @@ class TaskQueue
}
}
/**
* Returns true if the queue is empty.
*
* @return bool
*/
public function isEmpty()
{
return !$this->queue;
}
/**
* Adds a task to the queue that will be executed the next time run is
* called.
*
* @param callable $task
*/
public function add(callable $task)
{
$this->queue[] = $task;
}
/**
* Execute all of the pending task in the queue.
*/
public function run()
{
/** @var callable $task */

View File

@@ -0,0 +1,25 @@
<?php
namespace GuzzleHttp\Promise;
interface TaskQueueInterface
{
/**
* Returns true if the queue is empty.
*
* @return bool
*/
public function isEmpty();
/**
* Adds a task to the queue that will be executed the next time run is
* called.
*
* @param callable $task
*/
public function add(callable $task);
/**
* Execute all of the pending task in the queue.
*/
public function run();
}

View File

@@ -14,13 +14,17 @@ namespace GuzzleHttp\Promise;
* }
* </code>
*
* @return TaskQueue
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
*
* @return TaskQueueInterface
*/
function queue()
function queue(TaskQueueInterface $assign = null)
{
static $queue;
if (!$queue) {
if ($assign) {
$queue = $assign;
} elseif (!$queue) {
$queue = new TaskQueue();
}
@@ -210,7 +214,7 @@ function unwrap($promises)
*
* @param mixed $promises Promises or values.
*
* @return Promise
* @return PromiseInterface
*/
function all($promises)
{
@@ -243,7 +247,7 @@ function all($promises)
* @param int $count Total number of promises.
* @param mixed $promises Promises or values.
*
* @return Promise
* @return PromiseInterface
*/
function some($count, $promises)
{
@@ -299,7 +303,7 @@ function any($promises)
*
* @param mixed $promises Promises or values.
*
* @return Promise
* @return PromiseInterface
* @see GuzzleHttp\Promise\inspect for the inspection state array format.
*/
function settle($promises)
@@ -337,7 +341,7 @@ function settle($promises)
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return Promise
* @return PromiseInterface
*/
function each(
$iterable,
@@ -363,7 +367,7 @@ function each(
* @param callable $onFulfilled
* @param callable $onRejected
*
* @return mixed
* @return PromiseInterface
*/
function each_limit(
$iterable,
@@ -387,7 +391,7 @@ function each_limit(
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return mixed
* @return PromiseInterface
*/
function each_limit_all(
$iterable,
@@ -441,60 +445,13 @@ function is_settled(PromiseInterface $promise)
}
/**
* Creates a promise that is resolved using a generator that yields values or
* promises (somewhat similar to C#'s async keyword).
* @see Coroutine
*
* When called, the coroutine function will start an instance of the generator
* and returns a promise that is fulfilled with its final yielded value.
* @param callable $generatorFn
*
* Control is returned back to the generator when the yielded promise settles.
* This can lead to less verbose code when doing lots of sequential async calls
* with minimal processing in between.
*
* use GuzzleHttp\Promise;
*
* function createPromise($value) {
* return new Promise\FulfilledPromise($value);
* }
*
* $promise = Promise\coroutine(function () {
* $value = (yield createPromise('a'));
* try {
* $value = (yield createPromise($value . 'b'));
* } catch (\Exception $e) {
* // The promise was rejected.
* }
* yield $value . 'c';
* });
*
* // Outputs "abc"
* $promise->then(function ($v) { echo $v; });
*
* @param callable $generatorFn Generator function to wrap into a promise.
*
* @return Promise
* @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
* @return PromiseInterface
*/
function coroutine(callable $generatorFn)
{
$generator = $generatorFn();
return __next_coroutine($generator->current(), $generator)->then();
}
/** @internal */
function __next_coroutine($yielded, \Generator $generator)
{
return promise_for($yielded)->then(
function ($value) use ($generator) {
$nextYield = $generator->send($value);
return $generator->valid()
? __next_coroutine($nextYield, $generator)
: $value;
},
function ($reason) use ($generator) {
$nextYield = $generator->throw(exception_for($reason));
// The throw was caught, so keep iterating on the coroutine
return __next_coroutine($nextYield, $generator);
}
);
return new Coroutine($generatorFn);
}