Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i get some data from the session #61

Open
sq-dev opened this issue Feb 19, 2022 · 1 comment · May be fixed by #90
Open

how can i get some data from the session #61

sq-dev opened this issue Feb 19, 2022 · 1 comment · May be fixed by #90

Comments

@sq-dev
Copy link

sq-dev commented Feb 19, 2022

Hello, can I get some data from the session at once
F.E:
$bot->getUserDataItem(['test', 'test1'], function ($test, $test1){

});
very inconvenient to get them one by one

@awohsen
Copy link
Contributor

awohsen commented Apr 6, 2023

$requests = [];
$requests[] = $ctx->getUserDataItem('name');
$requests[] = $ctx->getUserDataItem('number');
\React\Promise\all($requests)->then(function ($result){
    var_dump($result);

    // returns: array(2) {
    //  [0]=>
    //  NULL
    //  [1]=>
    //  NULL
    //}
});

Also, it's possible with https://github.com/reactphp/async:

$requests = [];
$requests[] = $ctx->getUserDataItem('name');
$requests[] = $ctx->getUserDataItem('number');

$result = \React\Async\await(\React\Promise\all($requests));

var_dump($result);
// returns: array(2) {
//  [0]=>
//  NULL
//  [1]=>
//  NULL
//}

or:

coroutine(function () use ($ctx){
    $requests = [];
    $requests[] = $ctx->getUserDataItem('name');
    $requests[] = $ctx->getUserDataItem('number');

    $result = yield \React\Promise\all($requests);

    var_dump($result);
    // returns: array(2) {
    //  [0]=>
    //  NULL
    //  [1]=>
    //  NULL
    //}
});

or:

coroutine(function () use ($ctx) {
  try {
      $name = yield $ctx->getUserDataItem('name');
      $number = yield $ctx->getUserDataItem('number');
      var_dump($name, $number);

  } catch (\Exception $err) {
      echo $err->getMessage();
  }
});

@awohsen awohsen linked a pull request Jul 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants