Thruway\Role\Callee::processResultAsPromise PHP Метод

processResultAsPromise() приватный Метод

Process a result as a promise
private processResultAsPromise ( React\Promise\PromiseInterface $promise, Thruway\Message\InvocationMessage $msg, ClientSession $session, array $registration )
$promise React\Promise\PromiseInterface
$msg Thruway\Message\InvocationMessage
$session Thruway\ClientSession
$registration array
    private function processResultAsPromise(PromiseInterface $promise, InvocationMessage $msg, ClientSession $session, $registration)
    {
        $promise->then(function ($promiseResults) use($msg, $session) {
            $options = new \stdClass();
            if ($promiseResults instanceof Result) {
                $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $promiseResults->getArguments(), $promiseResults->getArgumentsKw());
            } else {
                $promiseResults = is_array($promiseResults) ? $promiseResults : [$promiseResults];
                $promiseResults = !$this::is_list($promiseResults) ? [$promiseResults] : $promiseResults;
                $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $promiseResults);
            }
            $session->sendMessage($yieldMsg);
        }, function ($e) use($msg, $session, $registration) {
            if ($e instanceof \Exception) {
                $this->processExceptionFromRPCCall($session, $msg, $registration, $e);
                return;
            }
            $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
            $errorMsg->setErrorURI($registration['procedure_name'] . '.error');
            $session->sendMessage($errorMsg);
        }, function ($results) use($msg, $session, $registration) {
            $options = new \stdClass();
            $options->progress = true;
            if ($results instanceof Result) {
                $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $results->getArguments(), $results->getArgumentsKw());
            } else {
                $results = is_array($results) ? $results : [$results];
                $results = !$this::is_list($results) ? [$results] : $results;
                $yieldMsg = new YieldMessage($msg->getRequestId(), $options, $results);
            }
            $session->sendMessage($yieldMsg);
        });
    }