Improve docs

This commit is contained in:
Daniil Gentili 2020-02-25 20:47:36 +01:00
parent e8cd2a7bb5
commit 7a8bc74239
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 34 additions and 2 deletions

View File

@ -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
<a href="https://docs.madelineproto.xyz/docs/USING_METHODS.html">Next section</a>

View File

@ -62,4 +62,4 @@ $MadelineProto->logger($message, $level);
By default, `$level` is `\danog\MadelineProto\Logger::NOTICE`.
<a href="https://docs.madelineproto.xyz/docs/CALLS.html">Next section</a>
<a href="https://docs.madelineproto.xyz/docs/CALLS.html">Next section</a>

View File

@ -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();