Update docs
This commit is contained in:
parent
9754f506d3
commit
dbb560f13e
@ -16,6 +16,7 @@ Powered by [amphp](https://amphp.org), MadelineProto wraps the AMPHP APIs to pro
|
||||
* [Async in callback handler](#async-in-callback-handler)
|
||||
* [Wrapped async](#wrapped-async)
|
||||
* [Multiple async](#multiple-async)
|
||||
* [ArrayAccess async](#arrayaccess-async)
|
||||
* [Ignored async](#ignored-async)
|
||||
* [Blocking async](#blocking-async)
|
||||
* [MadelineProto and AMPHP async APIs](#madelineproto-and-amphp-async-apis)
|
||||
@ -194,6 +195,64 @@ The result of this will be an array of results, whose type is determined by the
|
||||
|
||||
The order of method calls can be guaranteed (server-side, not by MadelineProto) by using [call queues](USING_METHODS.html#queues).
|
||||
|
||||
### ArrayAccess async
|
||||
|
||||
You can do async ArrayAccess on promises.
|
||||
|
||||
Now instead of doing this:
|
||||
```php
|
||||
$id = (yield $MadelineProto->getPwrChat('danogentili'))['bot_api_id'];
|
||||
```
|
||||
|
||||
You can simply do this:
|
||||
```php
|
||||
$id = yield $MadelineProto->getPwrChat('danogentili')['bot_api_id'];
|
||||
```
|
||||
|
||||
Setting attributes asynchronously is also supported (it's kind of useless, but it's useful if you have some custom logic, like for example a method that returns a custom ArrayAccess class with a set method that does something magical).
|
||||
```php
|
||||
$Id = yield $MadelineProto->getPwrChat('danogentili')['bot_api_id'] = 'pony';
|
||||
```
|
||||
|
||||
isset and unset aren't supported due to the fact that in PHP, isset and unset aren't proper functions but language constructs (logically).
|
||||
You have to do this, instead:
|
||||
```php
|
||||
$set = isset((yield $MadelineProto->getPwrChat('danogentili'))['bot_api_id']);
|
||||
```
|
||||
|
||||
or
|
||||
```php
|
||||
$result = yield $MadelineProto->getPwrChat('danogentili');
|
||||
$set = isset($result['bot_api_id']);
|
||||
```
|
||||
|
||||
Also, `ArrayAccess` on raw generators still isn't supported unless you wrap them in a coroutine using `$MadelineProto->call`:
|
||||
```php
|
||||
public function ponyAsync()
|
||||
{
|
||||
return yield $MadelineProto->get_info('danogentili');
|
||||
}
|
||||
// public function onUpdateNewMessage....
|
||||
|
||||
// WILL NOT WORK
|
||||
$set = yield $this->ponyAsync()['id'];
|
||||
|
||||
// Will work
|
||||
$set = (yield $this->ponyAsync())['id'];
|
||||
|
||||
// Will work
|
||||
$set = $MadelineProto->call(yield $this->ponyAsync())['id'];
|
||||
|
||||
public function pony()
|
||||
{
|
||||
return $MadelineProto->call($this->ponyAsync());
|
||||
}
|
||||
|
||||
// Will work
|
||||
$set = yield $this->pony()['id'];
|
||||
```
|
||||
|
||||
|
||||
### Blocking async
|
||||
```php
|
||||
$result = blocking_function();
|
||||
|
@ -70,6 +70,7 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro
|
||||
* [Async in callback handler](https://docs.madelineproto.xyz/docs/ASYNC.html#async-in-callback-handler)
|
||||
* [Wrapped async](https://docs.madelineproto.xyz/docs/ASYNC.html#wrapped-async)
|
||||
* [Multiple async](https://docs.madelineproto.xyz/docs/ASYNC.html#multiple-async)
|
||||
* [ArrayAccess async](https://docs.madelineproto.xyz/docs/ASYNC.html#arrayaccess-async)
|
||||
* [Ignored async](https://docs.madelineproto.xyz/docs/ASYNC.html#ignored-async)
|
||||
* [Blocking async](https://docs.madelineproto.xyz/docs/ASYNC.html#blocking-async)
|
||||
* [MadelineProto and AMPHP async APIs](https://docs.madelineproto.xyz/docs/ASYNC.html#madelineproto-and-amphp-async-apis)
|
||||
|
Loading…
Reference in New Issue
Block a user