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

guzzle/promises #66

Closed
sm2017 opened this issue Oct 16, 2016 · 11 comments
Closed

guzzle/promises #66

sm2017 opened this issue Oct 16, 2016 · 11 comments
Labels

Comments

@sm2017
Copy link

sm2017 commented Oct 16, 2016

How can I convert guzzle/promises to reactphp/promise ?
As there is no done() method for guzzle/promises , I want to convert it to reactphp/promise

// $guzzlePromise is an instance of GuzzleHttp\Promise\Promise and is a result of third party library
$reactPromise = convert($guzzlePromise);
@WyriHaximus
Copy link
Member

Using react/promise ^2.4 while doing $reactPromise = \React\Promise\resolve($guzzlePromise); will make react/promise convert it for you.

@sm2017
Copy link
Author

sm2017 commented Oct 17, 2016

@WyriHaximus thanks for your reply
But there is a problem in this solution , now there is no difference between done() and then just done() returns void

I want to have uncaught exceptions

$guzzlePromise = new \GuzzleHttp\Promise\Promise();
$guzzlePromise
    ->then(function ($value) {
        throw new \Exception($value)
    });

$guzzlePromise->resolve('test');//Third party library

$reactPromise = \React\Promise\resolve($guzzlePromise)
    ->done();

As I use done() I expect Fatal error: Uncaught exception 'Exception' but there is no fatal error just a rejected promise

I want to tell more details about my problem
I use a third party library based on \GuzzleHttp\Promise\Promise , My application handle errors with exceptions and I have a Uncaught exception handler to manage them , So sometimes I need to consume promise , something like done() to force promise throws exceptions instead of reject promise

1- How can I do this with React\Promise
2- Can I do this in \GuzzleHttp\Promise\Promise

@jsor
Copy link
Member

jsor commented Oct 17, 2016

You need to cast to a React\Promise before calling thenon it.

$guzzlePromise = new \GuzzleHttp\Promise\Promise();

$reactPromise = \React\Promise\resolve($guzzlePromise)
    ->then(function ($value) {
        throw new \Exception($value)
    })
    ->done();

$guzzlePromise->resolve('test');//Third party library

@sm2017
Copy link
Author

sm2017 commented Oct 17, 2016

@jsor thanks for your reply
I run your code but there is no Fatal error: Uncaught exception 'Exception'
Where is my problem?! I check that throw new \Exception($value) is executed

This exception caught by guzzlehttp/promises/src/Promise.php:214

@jsor
Copy link
Member

jsor commented Oct 17, 2016

Sorry, i replied too fast :/
Since GuzzleHttp\Promise\Promise provides no done, it's not possible to let rejections bubble out.

@sm2017
Copy link
Author

sm2017 commented Oct 17, 2016

@jsor thank you
Can you please see this issue aws/aws-sdk-php#1105

@jsor
Copy link
Member

jsor commented Oct 24, 2016

I've proposed #68 which uses done() instead of then()if available when resolving foreign thenables. This solves this issue when merged and guzzlehttp/promises implements done().

@jsor jsor closed this as completed Oct 24, 2016
@sm2017
Copy link
Author

sm2017 commented Oct 25, 2016

So guzzlehttp/promises must be implement done() otherwise it dont works?
I understand right?

@WyriHaximus
Copy link
Member

Correct

@sm2017
Copy link
Author

sm2017 commented Oct 25, 2016

@jsor @WyriHaximus
Thanks a lot

@sm2017
Copy link
Author

sm2017 commented Nov 1, 2016

guzzle/promises#44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants