diff --git a/src/danog/MadelineProto/Async/AsyncParameters.php b/src/danog/MadelineProto/Async/AsyncParameters.php index 62264819..05e8c703 100644 --- a/src/danog/MadelineProto/Async/AsyncParameters.php +++ b/src/danog/MadelineProto/Async/AsyncParameters.php @@ -18,8 +18,6 @@ namespace danog\MadelineProto\Async; -use Amp\Success; - /** * Async parameters class. * @@ -53,17 +51,9 @@ class AsyncParameters extends Parameters return $this->refetchable; } - public function getParameters(): \Generator + public function getParameters() { $callable = $this->callable; - $params = $callable(); - - if ($params instanceof \Generator) { - $params = yield coroutine($params); - } else { - $params = yield new Success($params); - } - - return $params; + return yield $callable(); } } diff --git a/src/danog/MadelineProto/Async/Parameters.php b/src/danog/MadelineProto/Async/Parameters.php index 400792a2..f708fb9f 100644 --- a/src/danog/MadelineProto/Async/Parameters.php +++ b/src/danog/MadelineProto/Async/Parameters.php @@ -19,7 +19,6 @@ namespace danog\MadelineProto\Async; use Amp\Promise; -use function Amp\call; /** * Parameters module. @@ -37,23 +36,13 @@ abstract class Parameters * * @return Promise */ - public function fetchParameters(): Promise - { - return call([$this, 'fetchParametersAsync']); - } - - /** - * Fetch parameters asynchronously. - * - * @return \Generator - */ - public function fetchParametersAsync(): \Generator + public function fetchParameters() { $refetchable = $this->isRefetchable(); if ($this->params && !$refetchable) { return $this->params; } - $params = yield call([$this, 'getParameters']); + $params = yield $this->getParameters(); if (!$refetchable) { $this->params = $params; @@ -74,5 +63,5 @@ abstract class Parameters * * @return \Generator */ - abstract public function getParameters(): \Generator; + abstract public function getParameters(); } diff --git a/src/danog/MadelineProto/Loop/Connection/CheckLoop.php b/src/danog/MadelineProto/Loop/Connection/CheckLoop.php index 1c9e3df5..6bfa6036 100644 --- a/src/danog/MadelineProto/Loop/Connection/CheckLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/CheckLoop.php @@ -21,7 +21,6 @@ namespace danog\MadelineProto\Loop\Connection; use Amp\Deferred; use danog\MadelineProto\Logger; use danog\MadelineProto\Loop\Impl\ResumableSignalLoop; -use function Amp\call; /** * RPC call status check loop. @@ -30,7 +29,7 @@ use function Amp\call; */ class CheckLoop extends ResumableSignalLoop { - public function loop(): \Generator + public function loop() { $API = $this->API; $datacenter = $this->datacenter; diff --git a/src/danog/MadelineProto/Loop/Connection/HttpWaitLoop.php b/src/danog/MadelineProto/Loop/Connection/HttpWaitLoop.php index ae3b151f..b0bdb504 100644 --- a/src/danog/MadelineProto/Loop/Connection/HttpWaitLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/HttpWaitLoop.php @@ -31,7 +31,7 @@ use danog\MadelineProto\Stream\MTProtoTransport\HttpStream; */ class HttpWaitLoop extends ResumableSignalLoop { - public function loop(): \Generator + public function loop() { $API = $this->API; $datacenter = $this->datacenter; diff --git a/src/danog/MadelineProto/Loop/Connection/ReadLoop.php b/src/danog/MadelineProto/Loop/Connection/ReadLoop.php index b613aebf..c9aaefa5 100644 --- a/src/danog/MadelineProto/Loop/Connection/ReadLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/ReadLoop.php @@ -26,7 +26,6 @@ use danog\MadelineProto\Loop\Impl\SignalLoop; use danog\MadelineProto\MTProtoTools\Crypt; use danog\MadelineProto\NothingInTheSocketException; use danog\MadelineProto\Tools; -use function Amp\call; /** * Socket read loop. @@ -38,7 +37,7 @@ class ReadLoop extends SignalLoop use Tools; use Crypt; - public function loop(): \Generator + public function loop() { $API = $this->API; $datacenter = $this->datacenter; @@ -46,7 +45,7 @@ class ReadLoop extends SignalLoop $this->startedLoop(); $API->logger->logger("Entered read loop in DC {$datacenter}", Logger::ULTRA_VERBOSE); - $timeout = $API->settings['connection_settings'][isset($API->settings['connection_settings'][$datacenter]) ? $datacenter : 'all']['timeout']; + //$timeout = $API->settings['connection_settings'][isset($API->settings['connection_settings'][$datacenter]) ? $datacenter : 'all']['timeout']; while (true) { try { @@ -110,12 +109,7 @@ class ReadLoop extends SignalLoop } } - public function readMessage(): Promise - { - return call([$this, 'readMessageAsync']); - } - - public function readMessageAsync(): \Generator + public function readMessage() { $API = $this->API; $datacenter = $this->datacenter; diff --git a/src/danog/MadelineProto/Loop/Connection/UpdateLoop.php b/src/danog/MadelineProto/Loop/Connection/UpdateLoop.php index 00904a7d..31b5fcdb 100644 --- a/src/danog/MadelineProto/Loop/Connection/UpdateLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/UpdateLoop.php @@ -31,7 +31,7 @@ class UpdateLoop extends ResumableSignalLoop { use \danog\MadelineProto\Tools; - public function loop(): \Generator + public function loop() { $API = $this->API; $datacenter = $this->datacenter; @@ -57,7 +57,7 @@ class UpdateLoop extends ResumableSignalLoop } } if (time() - $API->last_getdifference > $timeout) { - if (!yield $this->call($API->get_updates_difference_async())) { + if (!yield $API->get_updates_difference_async()) { return false; } } diff --git a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php index 5deb7b52..acb9f822 100644 --- a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php @@ -72,7 +72,7 @@ class WriteLoop extends ResumableSignalLoop } } - public function unencryptedWriteLoopAsync(): \Generator + public function unencryptedWriteLoopAsync() { $API = $this->API; $datacenter = $this->datacenter; diff --git a/src/danog/MadelineProto/Loop/Impl/ResumableSignalLoop.php b/src/danog/MadelineProto/Loop/Impl/ResumableSignalLoop.php index 9a54369b..05d1b344 100644 --- a/src/danog/MadelineProto/Loop/Impl/ResumableSignalLoop.php +++ b/src/danog/MadelineProto/Loop/Impl/ResumableSignalLoop.php @@ -64,9 +64,10 @@ abstract class ResumableSignalLoop extends SignalLoop implements ResumableLoopIn return; } } + /* if ($expected) { - //var_dump("=======", "resume $watcherId ".get_class($this)." DC {$this->datacenter} diff ".(microtime(true) - $expected).": expected $expected, actual ".microtime(true)); - } + //var_dump("=======", "resume $watcherId ".get_class($this)." DC {$this->datacenter} diff ".(microtime(true) - $expected).": expected $expected, actual ".microtime(true)); + }*/ if ($this->resume) { $resume = $this->resume; $this->resume = null; diff --git a/src/danog/MadelineProto/Loop/LoopInterface.php b/src/danog/MadelineProto/Loop/LoopInterface.php index 18d6b531..d15b9384 100644 --- a/src/danog/MadelineProto/Loop/LoopInterface.php +++ b/src/danog/MadelineProto/Loop/LoopInterface.php @@ -37,5 +37,5 @@ interface LoopInterface * * @return void */ - public function loop(): \Generator; + public function loop(); } diff --git a/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php b/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php index 5b6aa5ad..bf56a97a 100644 --- a/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php +++ b/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php @@ -25,7 +25,6 @@ use Amp\Success; use danog\MadelineProto\Exception; use danog\MadelineProto\TL\TLCallback; use danog\MadelineProto\Tools; -use function Amp\call; /** * Manages upload and download of files. @@ -460,19 +459,14 @@ class ReferenceDatabase implements TLCallback return $this->refreshReferenceInternal($this->serializeLocation($locationType, $location)); } - public function refreshReferenceInternal(string $location): Promise + public function refreshReferenceInternal(string $location) { if (isset($this->refreshed[$location])) { $this->API->logger->logger('Reference already refreshed!', \danog\MadelineProto\Logger::VERBOSE); - return new Success($this->db[$location]['reference']); + return $this->db[$location]['reference']; } - return call([$this, 'refreshReferenceInternalGenerator'], $location); - } - - public function refreshReferenceInternalGenerator(string $location): \Generator - { ksort($this->db[$location]['origins']); $count = 0; @@ -497,7 +491,6 @@ class ReferenceDatabase implements TLCallback $this->API->full_chats[$origin['peer']]['last_update'] = 0; } $this->API->get_full_info($origin['peer']); - yield new Success(0); break; // Peer (default photo ID) case self::USER_PHOTO_ORIGIN: @@ -546,14 +539,14 @@ class ReferenceDatabase implements TLCallback return $deferred->promise(); } - public function getReference(int $locationType, array $location): Promise + public function getReference(int $locationType, array $location) { $locationString = $this->serializeLocation($locationType, $location); if (!isset($this->db[$locationString]['reference'])) { if (isset($location['file_reference'])) { $this->API->logger->logger("Using outdated file reference for location of type $locationType object {$location['_']}", \danog\MadelineProto\Logger::ULTRA_VERBOSE); - return new Success($location['file_reference']); + return $location['file_reference']; } throw new \danog\MadelineProto\Exception("Could not find file reference for location of type $locationType object {$location['_']}"); @@ -564,7 +557,7 @@ class ReferenceDatabase implements TLCallback return $this->refreshReferenceInternal($locationString); } - return new Success($this->db[$locationString]['reference']); + return $this->db[$locationString]['reference']; } private function serializeLocation(int $locationType, array $location)