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

What the sense in ReactPHP and it is Promises if QueryBus works synchronously? #189

Closed
BonBonSlick opened this issue Jun 29, 2018 · 9 comments

Comments

@BonBonSlick
Copy link

BonBonSlick commented Jun 29, 2018

I have tested 2 queries

`$this->queryBus->dispatch(new GetUserList( ))->then(
            function($result){
                dump($result); // some result
            }
        );

        $this->queryBus->dispatch( new GetUserList( ))->then(
            function($result)  {
                dump($result); // empty should be
            }
        )
        ;`

for first one handler i put sleep for 5 seconds, and here results are

//first - should be last, coz results + sleep
Paginator {#3327 ▼
...
}
//second, should be first, because no sleep + empty results
[]

Maybe i missed something, please tell me please.

@BonBonSlick BonBonSlick changed the title What th sense in React and it is Promises if QueryBus work synchronously? What the sense in ReactPHP and it is Promises if QueryBus works synchronously? Jun 29, 2018
@prolic
Copy link
Member

prolic commented Jun 30, 2018 via email

@BonBonSlick
Copy link
Author

BonBonSlick commented Jun 30, 2018

@prolic thank you for your response, i still do not get it.
What should i note?
Can you tell me please how to avoid promises, or use asynchronous?

@prolic
Copy link
Member

prolic commented Jul 3, 2018

You can wrap the query bus with your own implementation, so that you wrap the promise and return the real value. This should be very easy to write in a few minutes. I think someone posted the implementation for this already somewhere, but I can't remember.

About the initial question, I think you should use done() and not then() - see https://sergeyzhuk.me/2017/06/16/phpreact-promises/

@fritz-gerneth
Copy link
Contributor

reactphp/promise#43 for a similar question. E.g. you have to make the async code yourself. For synchronous code the promise is still synchronous too.

@BonBonSlick
Copy link
Author

@prolic Method 'done' not found in \React\Promise\PromiseInterface less... (Ctrl+F1 Alt+T)
Referenced method is not found in subject class.

@fritz-gerneth
Copy link
Contributor

done is only a part of of PromiseInterface since v3. Before this (v2) it was part of the ExtendedPromiseInterface. When you'll return a Promise, it will both interfaces though.

@BonBonSlick
Copy link
Author

BonBonSlick commented Jul 3, 2018

Thank you for clarification.
I think it would be nice idea to add some extra examples for bus and event. Sync / async, and how to write tests for these features. Also add more info from https://github.com/reactphp/promise or at least some links to point where people should search.

@prolic
Copy link
Member

prolic commented Oct 22, 2018

@BonBonSlick @codeliner wanna provide some docs? otherwise it's just another issue sitting here for years :)

@BonBonSlick
Copy link
Author

It is ok, we changed to symfony messenger. Use only your store everything else written from scratch

@prolic prolic closed this as completed Oct 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants