reactphp / promise

Promises/A implementation for PHP.
https://reactphp.org/promise/
MIT License
2.38k stars 146 forks source link

Call promise twice #167

Closed cheeghi closed 4 years ago

cheeghi commented 4 years ago

Hi, can I call a reactphp promise twice? I tried and it seems to work just fine, I was just wondering if there is any drawback doing it. Here an example with reactphp-buzz client:

use Clue\React\Buzz\Browser;
use Exception;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;

$loop = Factory::create();
$browser = new Browser($loop);

$promise = $browser->get('https://google.it');

$promise->then(
    function (ResponseInterface $response) {
        var_dump('Response received', $response);
    },
    function (Exception $error) {
        var_dump('There was an error', $error->getMessage());
    }
);

$promise->then(
    function (ResponseInterface $response) {
        var_dump('Response received', $response);
    },
    function (Exception $error) {
        var_dump('There was an error', $error->getMessage());
    }
);

$loop->run();

Thank you in advance.

WyriHaximus commented 4 years ago

Hey @cheeghi sure you can do that, infact this is by design. The catch however is that if you do this your application needs to be know you're doing this and it has to be by design.

cheeghi commented 4 years ago

Perfect, thank you very much!