These are chat archives for reactphp/react

3rd
Aug 2016
Taras Lisennk
@Lisennk
Aug 03 2016 17:11
Hello
Anybody here?
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:12
me
@Taras-S wazzup man?
Taras Lisennk
@Lisennk
Aug 03 2016 17:12
ахах)
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:13
@SerafimArts what a happen, bro?
Taras Lisennk
@Lisennk
Aug 03 2016 17:13
give me a sec)
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:13
kk np
Taras Lisennk
@Lisennk
Aug 03 2016 17:14
may i write in rus, or there is someone except you?)
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:15
nope
i dont know rus lang
speak eng plz
Taras Lisennk
@Lisennk
Aug 03 2016 17:20

kind of шиза, ну лан)

I use this method that return react promise:
http://coderstephen.github.io/slack-client/api/source-class-Slack.ApiClient.html#293-307

On my client code, can i use something like this to get user:

$user = $api->getUserById('user-id-here');

Or i need to write a closure:

$user  = $api->getUserById($slackId)->then(function (User $user) {
            return $user;
 });

Oh, when i wrote it up, i understood that its kind of stupid question and of course i can use it without closure. Or not?

Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:21
u can wait result in event loop (like while true) but this is wrong way
no, you cant resolve promise in sync thread
Taras Lisennk
@Lisennk
Aug 03 2016 17:22
so what is the right way? I need to wrap all my code in closures?
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:22
or merge promises ;)
Taras Lisennk
@Lisennk
Aug 03 2016 17:23
how to do it? I know ReactPHP only a little bit
kirill?)
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:25
use function React\Promise\all;

all([$promiseA, $promiseB, $promiseC, $promiseD])->then(function($result) {
    // ...
});
@Taras-S ping
Taras Lisennk
@Lisennk
Aug 03 2016 17:27
Thanks. Can you write a short example with my use-case? I dont understand anything, sorry :(
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:27
never!!! arrrrghhhh!
:D
Taras Lisennk
@Lisennk
Aug 03 2016 17:27
pleaaaseeee
:)
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:28
@Taras-S nope, i use an Amp for sync parallel operations
but amp sucks
Taras Lisennk
@Lisennk
Aug 03 2016 17:29
right now the only one who suck its me with retarded React(
Write an example, please. As non-russian for non-russian :)
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:29
u can see a little ReactPhp examples in LaravelRUS/GitterBot repo
but i dont know what u wanna see
Taras Lisennk
@Lisennk
Aug 03 2016 17:32
i need to do something like this and dont wrap all code to closures
$user = $api->getUserById('user-id-here');
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:32
just do not use async operations
magic!
Taras Lisennk
@Lisennk
Aug 03 2016 17:34
i dont use async, but vendor based on it\
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:34
while(true)
but this is wrong way
i already said it
Taras Lisennk
@Lisennk
Aug 03 2016 17:36

And how to do it with while(true)? I use React EventLoop in code like this:

        $this->loop = Factory::create();
        $this->loop->run();

May be i can use it?

Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:38
$result = null;
$api->getUserById('....')->then(funciton($data) use (&$result) { $result = $data; });

while (!$result) {}

var_dump($result);
Taras Lisennk
@Lisennk
Aug 03 2016 17:39
Мда
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:39
what?
Taras Lisennk
@Lisennk
Aug 03 2016 17:39
Mda
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:40
i dont understand u
Taras Lisennk
@Lisennk
Aug 03 2016 17:40
ай ноу
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:40
cmon bro
hmmm
Taras Lisennk
@Lisennk
Aug 03 2016 17:41
But what if i use OOP? If i will wrap all code to resolve/reject, than it will be in functional style, not in OOP.
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:41
my example are broken
php are functional lang too
Taras Lisennk
@Lisennk
Aug 03 2016 17:43
but u cant mix it. Please, give me link to line where you use promises in your bot?
Taras Lisennk
@Lisennk
Aug 03 2016 17:46
Yeah, and its ugly as f*ck. May be there is feature like 'await' in React PHP EventLoop?
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:47
this is impossible
event loop contents a little more than 1 promise
like [p1, p2, p3]
every one second (as example) you process every item
if you stop one item for wait a result - u stop all items in your event loop
Taras Lisennk
@Lisennk
Aug 03 2016 17:49
Ok, i get it. Thanks to ReactPHP, now i suffer in PHP too, not only in JS xD
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:50
if you wanna a concurrency, you can use The Threads :D
Taras Lisennk
@Lisennk
Aug 03 2016 17:52
I need a sync way, dude. Or at least await. In my opinion, all this 'functional style' things is ugly.
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:53
await is an alias for all()function
lol
just use it if you want a behaviour like await operator in JS
Taras Lisennk
@Lisennk
Aug 03 2016 17:54

i get it, but its still ugly. I like C# way:

$data = await $api->getData();

And so on

But thanks anyway, @SerafimArts. Like always, helped me a lot.
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:56
async some() {
  var a = await fetch(...);
  var b = await fetch(...);

  return [a, b];
}
===
function some() {
    $a = fetch(...);
    $b = fetch(...);

    return all([$a, $b]);
}
@Taras-S this is SIMILAR examples
first js, second php
async functions with await usage returns...
PROMISE
magic!
Taras Lisennk
@Lisennk
Aug 03 2016 17:57
and i can use it in sync style?
... some code
$data = some();
... some code
Kirill Nesmeyanov
@SerafimArts
Aug 03 2016 17:58
no
some().then(data => {});
or
some()->then(function(data) { });
this is a similar usage of this js and php examples
Taras Lisennk
@Lisennk
Aug 03 2016 18:00
I get it. Its not await like in C#. But thanks, i will use it.