webstronauts/react-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Bundle for getting async support in Symfony through React's promises.

v1.0.0 2017-01-20 10:13 UTC

This package is not auto-updated.

Last update: 2018-10-30 14:45:35 UTC


README

This bundle is getting async support in Symfony through React's promises. When added to your kernel you can do things like this in your controller:

// src/Appbundle/Controller/DefaultController.php

namespace AppBundle\Controller;

use React\Promise\Deferred;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends controller
{
    public function indexAction()
    {
        $deferred = new Deferred();

        // Do some funky asynchronous programming here...
        $this->callAsynchronousMethod(function ($result) use ($deferred) {
            $deferred->resolve($result);
        });

        return $deferred->promise();
    }
}

Version Build Status Scrutinizer Code Quality Code Coverage StyleCI

Documentation

Installation

  1. Add this bundle to your composer.json:
php composer.phar require webstronauts/react-bundle
  1. Add this bundle to your application's kernel:
// app/ApplicationKernel.php

public function registerBundles()
{
    return array(
        // ...
        new Webstronauts\Bundle\ReactBundle\WebstronautsReactBundle(),
        // ...
    );
}
  1. There's no step 3! This is everything you need to do to make Symfony asynchronous.

Technical notes

This bundle listens to the kernel.view event for controller results and wraps it in a promise so either the resolved promise or any other result is returned and handled by Symfony as excepted. In case of a rejected promise, the corresponding exception is thrown.

Internally it uses an event-loop instance to add asynchronous execution of callbacks to Symfony. When any promises are unresolved, the event-loop keeps running on the kernel.terminate event. Keep in mind that with an incorrect configuration of your webserver, the response is returned after the kernel is terminated.

Tests

To run the test suite, you need install the dependencies via composer, then run PHPUnit.

composer install
php vendor/bin/phpunit

License

MIT © The Webstronauts