From 7a8bc742393a50f32acec02b8b0f8db31ada2028 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 25 Feb 2020 20:47:36 +0100 Subject: [PATCH] Improve docs --- docs/docs/ASYNC.md | 32 ++++++++++++++++++++++++++++++++ docs/docs/LOGGING.md | 2 +- docs/docs/LOGIN.md | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/docs/ASYNC.md b/docs/docs/ASYNC.md index 230f6d83..31fe10de 100644 --- a/docs/docs/ASYNC.md +++ b/docs/docs/ASYNC.md @@ -621,4 +621,36 @@ The return value of the callable can be: If the callable does not return anything, the loop will behave is if `GenericLoop::PAUSE` was returned. +#### PeriodicLoop + +If you simply want to execute an action every N seconds, [PeriodicLoop](https://github.com/danog/MadelineProto/blob/master/src/danog/MadelineProto/Loop/Generic/PeriodicLoop.php) is the way to go. +The constructor accepts four parameters: +```php + /** + * Constructor. + * + * @param \danog\MadelineProto\API $API Instance of MTProto class + * @param callable $callback Callback to call + * @param string $name Loop name + * @param int|float $timeout Loop timeout + */ + public function __construct($API, callable $callback, string $name, $timeout) { // ... +``` + +Example: +```php +use danog\MadelineProto\Loop\Generic\PeriodicLoop; +$loop = new PeriodicLoop( + $MadelineProto, + function () use (&$loop) { + yield $this->API->messages->sendMessage(['peer' => '...', 'message' => 'Hi every 2 seconds']); + }, + "My super loop", + 2 +); +$loop->start(); +``` +Unlike `GenericLoop`, the callback will **not** be bound to the GenericLoop instance. +You can still command the loop by using the pause/waitSignal methods from the outside or by capturing the loop instance in a closure like shown above. +s Next section \ No newline at end of file diff --git a/docs/docs/LOGGING.md b/docs/docs/LOGGING.md index 86a320bf..689452eb 100644 --- a/docs/docs/LOGGING.md +++ b/docs/docs/LOGGING.md @@ -62,4 +62,4 @@ $MadelineProto->logger($message, $level); By default, `$level` is `\danog\MadelineProto\Logger::NOTICE`. -Next section +Next section \ No newline at end of file diff --git a/docs/docs/LOGIN.md b/docs/docs/LOGIN.md index 6eac373f..2a5e49c8 100644 --- a/docs/docs/LOGIN.md +++ b/docs/docs/LOGIN.md @@ -34,7 +34,7 @@ If your account does get banned, write to [recover@telegram.org](mailto:recover@ There were cases when several **normal user accounts that did nothing wrong** were banned when telegram deployed a new spambot detection system: this is bad for the community, and it is bad for Telegram, so please do not abuse. -## Automatic ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)) +## Automatic ```php yield $MadelineProto->start();