Add method to stop loop
This commit is contained in:
parent
a79650a180
commit
db40848866
@ -5577,7 +5577,16 @@ class InternalDoc extends APIFactory
|
|||||||
return $this->__call(__FUNCTION__, [$callback, $extra]);
|
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
|
* @param string $message Message
|
||||||
*
|
*
|
||||||
|
@ -29,6 +29,12 @@ use danog\MadelineProto\Tools;
|
|||||||
trait Loop
|
trait Loop
|
||||||
{
|
{
|
||||||
private $loop_callback;
|
private $loop_callback;
|
||||||
|
/**
|
||||||
|
* Whether to stop the loop.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $stopLoop = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set loop callback (DEPRECATED).
|
* Set loop callback (DEPRECATED).
|
||||||
@ -164,7 +170,8 @@ trait Loop
|
|||||||
|
|
||||||
$this->logger->logger('Started update loop', \danog\MadelineProto\Logger::NOTICE);
|
$this->logger->logger('Started update loop', \danog\MadelineProto\Logger::NOTICE);
|
||||||
|
|
||||||
while (true) {
|
$this->stopLoop = false;
|
||||||
|
do {
|
||||||
$updates = $this->updates;
|
$updates = $this->updates;
|
||||||
$this->updates = [];
|
$this->updates = [];
|
||||||
foreach ($updates as $update) {
|
foreach ($updates as $update) {
|
||||||
@ -177,14 +184,25 @@ trait Loop
|
|||||||
|
|
||||||
if ($this->loop_callback !== null) {
|
if ($this->loop_callback !== null) {
|
||||||
$callback = $this->loop_callback;
|
$callback = $this->loop_callback;
|
||||||
$callback();
|
Tools::callForkDefer($callback());
|
||||||
}
|
}
|
||||||
yield $this->waitUpdate();
|
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
|
* @param string $message Message
|
||||||
*
|
*
|
||||||
|
@ -32,7 +32,7 @@ if (!isset($backtrace[0]["file"]) || !in_array(basename($backtrace[0]["file"]),
|
|||||||
if (isset($backtrace[1]["file"])) {
|
if (isset($backtrace[1]["file"])) {
|
||||||
@chdir(dirname($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);
|
file_put_contents($backtrace[0]["file"], $contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user