PHPDaemon\SockJS\Methods\Generic::acquire PHP Method

acquire() protected method

acquire
protected acquire ( callable $cb ) : void
$cb callable
return void
    protected function acquire($cb)
    {
        $this->appInstance->getkey('error:' . $this->sessId, function ($redis) use($cb) {
            if (!$redis) {
                $this->internalServerError();
                return;
            }
            if ($redis->result !== null) {
                $this->error((int) $redis->result);
                return;
            }
            if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 0) {
                $this->anotherConnectionStillOpen();
                return;
            }
            $this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use($cb) {
                if (!$redis) {
                    $this->internalServerError();
                    return;
                }
                if ($redis->result > 0) {
                    $this->anotherConnectionStillOpen();
                    return;
                }
                $this->appInstance->subscribe('w8in:' . $this->sessId, [$this, 'w8in'], function ($redis) use($cb) {
                    if (!$redis) {
                        $this->internalServerError();
                        return;
                    }
                    if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
                        $this->anotherConnectionStillOpen();
                        return;
                    }
                    $this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use($cb) {
                        if (!$redis) {
                            $this->internalServerError();
                            return;
                        }
                        if ($redis->result > 1) {
                            $this->anotherConnectionStillOpen();
                            return;
                        }
                        if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
                            $this->anotherConnectionStillOpen();
                            return;
                        }
                        $cb === null || $cb();
                    });
                });
            });
        });
    }