Note: This should be removed once GAPIC exposes the ability to execute
concurrent requests.

@access private
@experimental
@param array $args
@return PromiseInterface
516464
public function createSessionAsync(array $args)
    {
        $database = $this->pluck('database', $args);
        $opts = $this->addResourcePrefixHeader([], $database);
        $opts['credentialsWrapper'] = $this->credentialsWrapper;
        $transport = $this->spannerClient->getTransport();

        $request = new CreateSessionRequest([
            'database' => $database
        ]);

        $session = $this->pluck('session', $args, false);

        if ($session) {
            $sessionMessage = new Session($session);
            $request->setSession($sessionMessage);
        }

        return $transport->startUnaryCall(
            new Call(
                'google.spanner.v1.Spanner/CreateSession',
                Session::class,
                $request
            ),
            $opts
        );
    }
700
public function to($handler /*, $args… */)
    {
        $args = array_slice(func_get_args(), 1);

        return $this->then(
            function (Allocation $allocation) use ($handler, $args) {
                try {
                    $result = call_user_func_array($handler, $args);
                    $result = \React\Promise\resolve($result);
                    $result->then(array($allocation, 'releaseAll'), array($allocation, 'releaseAll'));
                } catch (\Exception $e) {
                    $result = new RejectedPromise($e);
                    $allocation->releaseAll();
                }

                return $result;
            }
        );
    }
809622
public function withArgs($args = [])
    {
        if (!is_array($args)) {
            $args = func_get_args();
        }

        $this->args = $args;
        return $this;
    }
489195
public function getPromise(): PromiseInterface
    {
        if (! $this->requestOrign && ! $this->promise) throw new RequestBuildExpection('please give a request.');
        if (! $this->promise) {
            $this->promise = $this->_getClient()->sendAsync($this->requestOrign, $this->requestOption);
        }
        if ($this->responseIsJson && ! $this->isJsonCallbackPassed) {
            array_unshift($this->callbackOfSuccess, function ($res) {
                return json_decode($res, true);
            });
            $this->isJsonCallbackPassed = true;
        }
        return $this->promise;
    }
286001
protected function initService(array $args = null) {
		if ($args === null) {
			return call_user_func($this->callback);
		}
		
		return call_user_func_array($this->callback, $args);
	}
251143
private function createPromiseForPush(PushInterface $push, RecipientInterface $recipient): PromiseInterface {
        return $this->client->sendAsync($this->prepareRequest($push->getMessage(), $recipient))
            ->otherwise(function (\Exception $exception) use ($push, $recipient) {
                $push->setFailedFor($recipient, $exception);
            });
    }
1050661
public static function cli($args)
    {
        $cwd = getcwd();
        $cli = new self($cwd);

        return $cli->run(array_slice($args, 1));
    }
1188907
public function forward(Argument $args)
    {
        $args = $this->protectArgs($args);
        $limit = $args['first'];
        $offset = $this->connectionBuilder->getOffsetWithDefault($args['after'], 0);

        // If we don't have a cursor or if it's not valid, then we must not use the slice method
        if (!\is_numeric($this->connectionBuilder->cursorToOffset($args['after'])) || !$args['after']) {
            $entities = \call_user_func($this->fetcher, $offset, $limit ? $limit + 1 : $limit);

            return $this->handleEntities($entities, function ($entities) use ($args) {
                return $this->connectionBuilder->connectionFromArray($entities, $args);
            });
        } else {
            $entities = \call_user_func($this->fetcher, $offset, $limit ? $limit + 2 : $limit);

            return $this->handleEntities($entities, function ($entities) use ($args, $offset) {
                return $this->connectionBuilder->connectionFromArraySlice($entities, $args, [
                    'sliceStart' => $offset,
                    'arrayLength' => $offset + \count($entities),
                ]);
            });
        }
    }
1225739
private function outerPromise(PromiseInterface $inner): Promise
    {
        $outer = new Promise(function () use ($inner) {
            // Our wait function invokes the inner's wait function, as as far
            // as callers are concerned there is only one promise.
            try {
                $inner->wait();
            } catch (\Exception $e) {
                // The inner promise handles all rejections.
            }
        });

        return $outer;
    }
3679
public function run(array $args) {
		foreach($this->calls as $call) {
			if($call instanceof \SuperClosure\SerializableClosure)
				$call = $call->getClosure();
			$res = call_user_func_array($call, array_merge([$this], $args));
			$this->executed++;
			if($res !== null)
				return $res;
			if(!$this->continue)
				return;
		}
	}
77353
public function set(...$args): RegistryInterface
    {
        $separator = '--'. md5(uniqid()) . '--';

        switch (count($args)) {
            case 0:
                //there's nothing to set
                return $this;
            case 1:
                if (is_array($args[0])) {
                    $this->data = $args[0];
                }
                return $this;
            default:
                $value = array_pop($args);
                return $this->setDot(implode($separator, $args), $value, $separator);
        }
    }
471175
public function handle(Message $message, array $options=[]) : PromiseInterface
    {
        $promise = new Promise(function () use (&$promise, $message, $options) {
            $promise->resolve(call_user_func(
                $this->callback,
                $message,
                $options
            ));
        });

        return $promise;
    }
589666
protected function initService(array $args = null) {
		if (is_object($this->prototype)) {
			return clone $this->prototype;
		}
		
		$copy = $this->prototype;
		return $copy;
	}
620856
public function performApiRequest(TelegramMethods $method): PromiseInterface
    {
        $this->logger->debug('Request for async API call, resetting internal values', [\get_class($method)]);
        $this->resetObjectValues();
        $option = $this->formConstructor->constructOptions($method);
        return $this->sendRequestToTelegram($method, $option)
            ->then(function (TelegramResponse $response) use ($method) {
                return $method::bindToObject($response, $this->logger);
            }, function ($error) {
                $this->logger->error($error);
                throw $error;
            });
    }
849715
public function proceed($args = null)
    {
        if(null === $args)
        {
            $args = $this->getArgs();
        }
        return call_user_func($this->nextProceed, $args);
    }
751276
private function prepare($args)
    {
        $bindings = array();

        // Two parameters (key, value).
        if (count($args) == 2) {
            $bindings[$args[0]] = $args[1];
        }
        // Array of parameters.
        elseif (is_array($args[0])) {
            $bindings = $args[0];
        }

        return $bindings;
    }
265619
protected function executePayload($payload, $args)
    {
        array_unshift($args, $this->wrapped);

        if ($payload instanceof Mutator) {
            /** @var $payload callable */
            $this->wrapped = call_user_func_array($payload, $args);

            return $this;
        } else {
            return call_user_func_array($payload, $args);
        }
    }