From 8e3df1e7bfeeb14c69ee7a1237decfc3a12b7dab Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 7 Feb 2023 19:19:50 +0100 Subject: [PATCH] Properly handle execution time limits (fixes "Must call resume() or throw() before calling suspend() again" errors) --- docs | 2 +- src/Shutdown.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs b/docs index a219e8a4f..846f4a037 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit a219e8a4f31000bf366993ab269b9ea2a95bbe2c +Subproject commit 846f4a03749d57ac166276445f95662dff45eb67 diff --git a/src/Shutdown.php b/src/Shutdown.php index faa0a0b77..4f5c30db5 100644 --- a/src/Shutdown.php +++ b/src/Shutdown.php @@ -20,6 +20,9 @@ declare(strict_types=1); namespace danog\MadelineProto; +use ReflectionClass; +use Revolt\EventLoop; + use function Amp\ByteStream\getStdin; /** @@ -48,6 +51,17 @@ final class Shutdown */ private static function shutdown(): void { + $obj = EventLoop::getSuspension(); + $reflection = new ReflectionClass($obj); + $reflection->getProperty('pending')->setValue($obj, false); + $obj = EventLoop::getDriver(); + $reflection = new ReflectionClass(AbstractDriver::class); + if (!$reflection->getProperty('callbackFiber')->isInitialized($obj) + || $reflection->getProperty('callbackFiber')->getValue($obj)->isTerminated() + ) { + $reflection->getMethod('createCallbackFiber')->invoke($obj); + } + foreach (self::$callbacks as $callback) { $callback(); }