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

unregister() публичный Метод

process unregister
public unregister ( ClientSession $session, string $Uri ) : Promise | false
$session Thruway\ClientSession
$Uri string
Результат React\Promise\Promise | false
    public function unregister(ClientSession $session, $Uri)
    {
        // TODO: maybe add an option to wait for pending calls to finish
        $registration = null;
        foreach ($this->registrations as $k => $r) {
            if (isset($r['procedure_name'])) {
                if ($r['procedure_name'] == $Uri) {
                    $registration =& $this->registrations[$k];
                    break;
                }
            }
        }
        if ($registration === null) {
            Logger::warning($this, "registration not found: " . $Uri);
            return false;
        }
        // we remove the callback from the client here
        // because we don't want the client to respond to any more calls
        $registration['callback'] = null;
        $futureResult = new Deferred();
        if (!isset($registration["registration_id"])) {
            // this would happen if the registration was never acknowledged by the router
            // we should remove the registration and resolve any pending deferreds
            Logger::error($this, "Registration ID is not set while attempting to unregister " . $Uri);
            // reject the pending registration
            $registration['futureResult']->reject();
            // TODO: need to figure out what to do in this off chance
            // We should still probably return a promise here that just rejects
            // there is an issue with the pending registration too that
            // the router may have a "REGISTERED" in transit and may still think that is
            // good to go - so maybe still send the unregister?
        }
        $requestId = Utils::getUniqueId();
        // save the request id so we can find this in the registration
        // list to call the deferred and remove it from the list
        $registration['unregister_request_id'] = $requestId;
        $registration['unregister_deferred'] = $futureResult;
        $unregisterMsg = new UnregisterMessage($requestId, $registration['registration_id']);
        $session->sendMessage($unregisterMsg);
        return $futureResult->promise();
    }