Add method to stop loop

This commit is contained in:
Daniil Gentili 2020-01-19 15:44:12 +01:00
parent a79650a180
commit db40848866
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 34 additions and 7 deletions

View File

@ -5577,7 +5577,16 @@ class InternalDoc extends APIFactory
return $this->__call(__FUNCTION__, [$callback, $extra]);
}
/**
* Close connection with server.
* Stop update loop.
*
* @return void
*/
public function stop(): void
{
$this->API->stop();
}
/**
* Close connection with client, connected via web.
*
* @param string $message Message
*

View File

@ -29,6 +29,12 @@ use danog\MadelineProto\Tools;
trait Loop
{
private $loop_callback;
/**
* Whether to stop the loop.
*
* @var boolean
*/
private $stopLoop = false;
/**
* Set loop callback (DEPRECATED).
@ -164,7 +170,8 @@ trait Loop
$this->logger->logger('Started update loop', \danog\MadelineProto\Logger::NOTICE);
while (true) {
$this->stopLoop = false;
do {
$updates = $this->updates;
$this->updates = [];
foreach ($updates as $update) {
@ -177,14 +184,25 @@ trait Loop
if ($this->loop_callback !== null) {
$callback = $this->loop_callback;
$callback();
Tools::callForkDefer($callback());
}
yield $this->waitUpdate();
}
} while (!$this->stopLoop);
$this->stopLoop = false;
}
/**
* Stop update loop.
*
* @return void
*/
public function stop(): void
{
$this->stopLoop = true;
$this->signalUpdate();
}
/**
* Close connection with server.
* Close connection with client, connected via web.
*
* @param string $message Message
*

View File

@ -32,11 +32,11 @@ if (!isset($backtrace[0]["file"]) || !in_array(basename($backtrace[0]["file"]),
if (isset($backtrace[1]["file"])) {
@chdir(dirname($backtrace[1]["file"]));
}
if ($contents = file_get_contents("https://phar.madelineproto.xyz/phar.php?v=new")) {
if ($contents = file_get_contents("https://phar.madelineproto.xyz/phar.php?v=new".rand(0, PHP_INT_MAX))) {
file_put_contents($backtrace[0]["file"], $contents);
}
Phar::interceptFileFuncs();
Phar::interceptFileFuncs();
Phar::mapPhar("'.$argv[2].'");
return require_once "phar://'.$argv[2].'/vendor/autoload.php";