Return function that apply changes in yieldables.
@param  mixed         $yielded
@param  array         $yieldables
@param  callable|null $next
@return mixed
492064
public static function getApplier($yielded, array $yieldables, callable $next = null)
    {
        return function (array $results) use ($yielded, $yieldables, $next) {
            foreach ($results as $hash => $resolved) {
                $current = &$yielded;
                foreach ($yieldables[$hash]['keylist'] as $key) {
                    $current = &$current[$key];
                }
                $current = $resolved;
                unset($current);
            }
            return $next ? $next($yielded) : $yielded;
        };
    }
812246
public function handle($request, Closure $next)
    {
        if (! Current::port()) {
            return $next($request);
        }

        $uri = ltrim(Current::requestPath(), '/');

        if (starts_with($uri, 'sv/res/')) {
            ResourceActivityEvent::dispatch($request);
        }

        return $next($request);
    }
984428
public function flatten()
    {
        return new Enumerator(
            function () {
                foreach ($this->each() as $k => $v) {
                    if (($v instanceof \Traversable) || is_array($v)) {
                        yield $k => Enumerator::from($v)->flatten();
                    } else {
                        yield $k => $v;
                    }
                }
            }
        );
    }
343925
public function call(string $method, $args): \Generator
    {
        $request = new Request();
        $request->id = $this->idSequence->current();
        $this->idSequence->next();
        $request->method = $method;
        $request->params = $args;

        $serializedRequest = Json::encode($this->mapper->dump($request));
        $this->pendingRequests[$request->id] = yield Recoil::strand();
        yield Recoil::execute($this->transport->send($serializedRequest));

        /** @var ResultResponse|ErrorResponse $response */
        $response = yield Recoil::suspend();

        if ($response instanceof ErrorResponse) {
            throw $response->error;
        }

        return $response->result;
    }
1219571
function promiseSequence(promiseFactories) {
    return __awaiter(this, void 0, void 0, function* () {
        const ret = [];
        for (const f of promiseFactories) {
            ret.push(yield f());
        }
        return ret;
    });
}
1194850
public function handle($request, Closure $next, $permissions = null, $any = false)
    {
        if (is_null($permissions)) {
            $permissions = $this->getPermissions($request);
            $anyPermission = $this->getAny($request);
        } else {
            $permissions = explode('|', $permissions); // Laravel 5.1 - Using parameters
            $anyPermission = $any;
        }

        if (is_null($this->user)) {
            return $this->forbiddenResponse();
        }

        if ($this->user->isSuperUser()) {
            return $next($request);
        }

        if (is_array($permissions) and count($permissions) > 0) {
            $canResult = true;

            foreach ($permissions as $permission) {
                $canPermission = $this->user->hasPermission($permission);

                // Check if any permission is enough
                if ($anyPermission and $canPermission) {
                    return $next($request);
                }

                $canResult = $canResult & $canPermission;
            }

            if (! $canResult) {
                return $this->forbiddenResponse();
            }
        }

        return $next($request);
    }
1144516
protected static function analyzeYieldFrom(
        StatementsAnalyzer $statements_analyzer,
        PhpParser\Node\Expr\YieldFrom $stmt,
        Context $context
    ) {
        if (self::analyze($statements_analyzer, $stmt->expr, $context) === false) {
            return false;
        }

        if (isset($stmt->expr->inferredType)) {
            $yield_from_type = null;

            foreach ($stmt->expr->inferredType->getTypes() as $atomic_type) {
                if ($yield_from_type === null) {
                    if ($atomic_type instanceof Type\Atomic\TGenericObject
                        && strtolower($atomic_type->value) === 'generator'
                        && isset($atomic_type->type_params[3])
                    ) {
                        $yield_from_type = clone $atomic_type->type_params[3];
                    } elseif ($atomic_type instanceof Type\Atomic\TArray) {
                        $yield_from_type = clone $atomic_type->type_params[1];
                    } elseif ($atomic_type instanceof Type\Atomic\ObjectLike) {
                        $yield_from_type = $atomic_type->getGenericValueType();
                    }
                } else {
                    $yield_from_type = Type::getMixed();
                }
            }

            // this should be whatever the generator above returns, but *not* the return type
            $stmt->inferredType = $yield_from_type ?: Type::getMixed();
        }

        return null;
    }
723305
public function first(callable $callback = null, $default = null)
    {
        foreach ($this->generator as $item) {
            if (!$callback || $callback($item)) {
                return $item;
            }
        }

        return $default;
    }
495357
public function findChildren(callable $callback, $depth = null, $level = null)
    {

        $level = $level ?: 0;

        foreach ($this->children as $child) {

            /** @var NodeInterface $child */
            if ($child->is($callback))
                yield $child;

            if ($depth === null || $level < $depth) {

                if ($child instanceof NodeInterface)
                    foreach ($child->findChildren($callback, $depth, $level + 1) as $subChild)
                        yield $subChild;
            }
        }
    }
776169
public function handle($request, Closure $next)
    {
        $route = $request->route();

        $this->router->substituteBindings($route);

        $this->substituteImplicitBindings($route);

        return $next($request);
    }
565801
private function yieldFilesInPath(SpecificationInterface $specification, string $path): Generator
    {
        $listContents = $this->filesystem->listContents($path);
        foreach ($listContents as $location) {
            if ($specification->isSatisfiedBy($location)) {
                yield $location;
            }

            if ($location['type'] === 'dir') {
                foreach ($this->yieldFilesInPath($specification, $location['path']) as $returnedLocation) {
                    yield $returnedLocation;
                }
            }
        }
    }
1059643
private function send(callable $function, ...$args): \Generator
    {
        while ($this->deferred) {
            try {
                yield $this->deferred->promise();
            } catch (\Throwable $exception) {
                // Ignore failure from another operation.
            }
        }

        if (!\is_resource($this->handle)) {
            throw new ConnectionException("The connection to the database has been closed");
        }

        $result = $function($this->handle, ...$args);

        if ($result === false) {
            throw new FailureException(\pg_last_error($this->handle));
        }

        $this->deferred = new Deferred;

        Loop::enable($this->poll);
        if (0 === $result) {
            Loop::enable($this->await);
        }

        try {
            $result = yield $this->deferred->promise();
        } finally {
            $this->deferred = null;
        }

        return $result;
    }
217595
public function handle($request, Closure $next)
    {
        $this->app->setLocale($this->getCurrentLocale($request));

        return $next($request);
    }
1192636
public function invoke($context, callable $next)
    {
        try {
            $next();
        } catch (CriticalErrorException $e) {
            // no retry for critical errors
            throw $e;
        } catch (MessageDeserializationException $e) {
            // no retry for invalid messages
            throw $e;
        } catch (\Throwable $t) {
            $messageId = $context->getMessageId();

            $numberOfRetries = $this->retryStorage->getFailuresForMessage($messageId);

            if ($this->retryPolicy->shouldGiveUp($numberOfRetries)) {
                $this->retryStorage->clearFailuresForMessage($messageId);

                $message = $context->getMessage();
                $message->setHeader(FirstLevelRetryHeaderTypeEnum::RETRIES, $numberOfRetries);

                throw $t;
            }

            $this->retryStorage->incrementFailuresForMessage($context->getMessageId());
            $context->abortReceiveOperation();
        }
    }
126478
public function map(callable $converter)
    {
        return new Enumerator(
            function () use($converter) {
                foreach ($this->each() as $k => $v) {
                    $v = call_user_func($converter, $v, $k);
                    yield $k => $v;
                }
            }
        );
    }
294911
protected function handleRequest(callable $next)
    {
        $this->route($this->request);
        return $next($this->request, $this->response);
    }
393678
private function processGeneratorContainerRunning(GeneratorContainer $gc)
    {
        // Check delay request yields
        if ($gc->key() === CoInterface::DELAY) {
            return $this->pool->addDelay($gc->current())
            ->then(function () use ($gc) {
                $gc->send(null);
                return $this->processGeneratorContainer($gc);
            });
        }

        // Now we normalize yielded value
        $yielded = YieldableUtils::normalize($gc->current());
        $yieldables = YieldableUtils::getYieldables($yielded, [], $this->runners);
        if (!$yieldables) {
            // If there are no yieldables, send yielded value back into generator
            $gc->send($yielded);
            // Continue
            return $this->processGeneratorContainer($gc);
        }

        // Chain resolver
        return $this->promiseAll($yieldables, $gc->key() !== CoInterface::SAFE)
        ->then(
            YieldableUtils::getApplier($yielded, $yieldables, [$gc, 'send']),
            [$gc, 'throw_']
        )->then(function () use ($gc, $yieldables) {
            // Continue
            $this->runners = array_diff_key($this->runners, $yieldables);
            return $this->processGeneratorContainer($gc);
        });
    }