Await for ReactPHP.

  • 2 heads
  • 1 release
  • git clone https://www.klva.cz/src/php/react-await.git
  • Fixed loop restoration. 7e053f6, 2 Sep 2018
    .gitattributes
    .gitignore
    await.php
    await.phpt
    composer.json
    LICENSE.md
    README.md

    Await for ReactPHP

    This is simple await implementation for ReactPHP. Whenever you need wait for a promise to be fulfilled in blocking manner, call await() on it.

    There is clue/block-react, which has more features, but breaks once there are more future ticks or timers on schedule. Also, this implementation restores running state of the loop.

    Usage

    // Inside running event loop:
    $connector = new React\Socket\Connector($loop);
    $connection = await($connector->connect('127.0.0.1:8080'), $loop);
    
    try {
        $connection = await($connector->connect('127.0.0.1:8080'), $loop);
    } catch (RuntimeException $e) {
        // Handling rejected promise.
    }
    

    Tests

    vendor/bin/tester await.phpt
    

    License

    Package is licensed as MIT, see LICENSE.md.