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 to implement progressive Results on RPC? #364

Open
treck opened this issue Jan 22, 2023 · 1 comment
Open

How to implement progressive Results on RPC? #364

treck opened this issue Jan 22, 2023 · 1 comment

Comments

@treck
Copy link

treck commented Jan 22, 2023

Hi.

I would like to work with progressive Results on RPC as the data amount is bigger as usual and the client can still process some minor datasets, but i didn't found a working example.

  1. A RPC is a method that typically returns one result. How to handle progress data in such a method?
  2. I read through the code and found that the RPC can return a Promise on which notify Callback will trigger such a progressive Result Message, but "notify" is marked DEPRECATED, and as PHP doesn't support async from scratch i see, that every Promise resolver is called in the constuctor leading to resolving the promise before it's returned. Am i wrong or did someone ever get this to work using Promises?

I would love to see some working progressive Call-Result with Thruway, if someone has one.

Regards,
Oliver

@treck
Copy link
Author

treck commented Jan 25, 2023

I found a working solution myself, but would like to know if there are easier solutions.

$loop = $this->loop;
        return new Promise(function (callable $resolve, callable $reject, callable $notify) use ($loop) {
        // $loop->futureTick(... is needed, cause resolver is executed immediately
            $loop->futureTick(function() use ($resolve, $notify) {
                for ($x=0;$x<5;$x++) {
                   $notify([$x, 'Progress No. ' . $x, rand(0,9999)]);
                    await(\React\Promise\Timer\sleep(0.001)); // without this StreamData doesn't get sent
                    sleep(2); // some blocking actions
                }
                $resolve(['Done']);
            });
        });

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

No branches or pull requests

1 participant