How to use async in MadelineProto Php?

Hi all. Trying to write a script that checks the availability of usernames telegram. For this is method account.checkUsername in API telegram. I for once need to check 100+ logins in a single thread it takes more than a minute. I decided to rewrite it to async.

Wrote this code, it works if I disable async. Include mode - stops working. If inside the foreach to make the var_dump that is the object generator.

$me = $MadelineProto->get_self();

handleUsers function($usernames, $MadelineProto)
 $i = 0;
 $count = count($usernames);
 while ($i < $count)
 yield $usernames[$i]['field_value'] => $MadelineProto->account->checkUsername(['username' => $usernames[$i]['field_value']]);

foreach (handleUsers($usernames, $MadelineProto) AS $login => $available)
 if ($available)
 // Available
 // Not available
April 3rd 20 at 17:45
2 answers
April 3rd 20 at 17:47
yield $usernames[$i]['field_value'] => $MadelineProto->account->['username' => $usernames[$i]['field_value']],1);

Maybe better way?
Perhaps a mistake in the writing above, but essentially better than cecati each user. And as far as I know, and even if the user renames, in you will find it under the old name, but in checkUsername only by name now.
I'm interested in is whether there is a cart with that name. The point is not the method, but the fact that my code does not work at all. It does not return a value at all. - Jalon.Casper commented on April 3rd 20 at 17:50
@ola, You it returns TRUE (it can be 1 or -1) or FALSE (0 or null), and what kind of response You require from the method?
Check $usernames[$i]['field_value'] there, the value is: 1, -1, 0, null, TRUE, FALSE - Reagan44 commented on April 3rd 20 at 17:53
@melyssa.Keebler, there returns a generator object - Jalon.Casper commented on April 3rd 20 at 17:56
@ola, what displays the Object.values() ?
Object is Your usernames

Oops, sorry, You piconets, I always can not help.
You have not specified the language. Wrote that PHP. But You have the same Python.
If I meet You not in that category, click "report". - Reagan44 commented on April 3rd 20 at 17:59
@melyssa.Keebleris php, keep you updated - Jalon.Casper commented on April 3rd 20 at 18:02
@ola, well then why yield ? As I understand it, $MadelineProto->async(true); yield not to please in the dock like so. - Reagan44 commented on April 3rd 20 at 18:05
@melyssa.Keebler, Object.values() - it's all js - Jalon.Casper commented on April 3rd 20 at 18:08
I was always of the opinion that if we are here not able to help, let us expert you invite.
I'll Call the expert using the button here.
Called allan.Kohler, the man knows his stuff and will help, hopefully.

Habr just needs to be a real help, because if no one can help and need help of expert, proven a special on his work, he will help.
Just all the experts can't be on all matters. - Reagan44 commented on April 3rd 20 at 18:11
@melyssa.Keebler, Welcome. Thank you for not forget and appreciate)
About the expert: how others don't know, I don't work in Habra and its subsidiary services, answer without any benefits and income for their work here. My blog - more details...

Regarding the question - write to the author. - ebony43 commented on April 3rd 20 at 18:14
April 3rd 20 at 17:49
Perhaps what is happening there race-condition or "race condition".

Try to get rid of yield and assign variables using all intermediate values.

The easiest way to check: two checks in a row with no cycle with intermediate variables and immediately after each - var_dump all variables.
Response codes the remote server - it is desirable also to.

In the extreme case - a sniffer and packet analysis: it is possible that the remote server has a limit on concurrent connections.

Find more questions by tags PHPTelegram