8000 Allow passing a react loop instance for minion's client to use by NeoVance · Pull Request #20 · Vinelab/minion · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ $m->run(
);
```

In existing applications it may be useful to be re-use an existing ReactPHP loop. You can pass in a LoopInterface like so:

```php
$loop = React\EventLoop\Factory::create();
$m = new Minion();
$m->run([], $loop);
```

## Usage
The idea behind Minion is to help structure your application and get it ready for scale
with real-time communication by using **providers** to *register RPCs* and *publish and subscribe to topics*
Expand Down
6 changes: 4 additions & 2 deletions src/Vinelab/Minion/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Psr\Log\NullLogger;
use Thruway\Logging\Logger;
use React\EventLoop\LoopInterface;

/**
* @author Abed Halawi <abed.halawi@vinelab.com>
Expand Down Expand Up @@ -37,10 +38,11 @@ class Client extends \Thruway\Peer\Client
*
* @param string $realm
* @param array $providers
* @param \React\EventLoop\LoopInterface $loop
*/
public function __construct($realm, array $providers)
public function __construct($realm, array $providers, LoopInterface $loop = null)
{
parent::__construct($realm);
parent::__construct($realm, $loop);

$this->providers = $providers;
}
Expand Down
12 changes: 8 additions & 4 deletions src/Vinelab/Minion/Minion.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Thruway\Transport\PawlTransportProvider;
use React\EventLoop\LoopInterface;

/**
* @author Abed Halawi <abed.halawi@vinelab.com>
Expand Down Expand Up @@ -64,30 +65,33 @@ public function getRegisteredProviders()
* Run the server.
*
* @param array $options
* @param \React\EventLoop\LoopInterface $loop
*
* @throws \Exception If encountered any failure starting the client.
*/
public function run($options = [])
public function run($options = [], LoopInterface $loop = null)
{
$this->mergeConfig($options);

// Print out our lovely minion.
echo $this->gimmeASCII()."\n";

$client = $this->newClient();
$client = $this->newClient($loop);
$client->addTransportProvider($this->newTransportProvider());

return $client->start($this->getConfig('debug'));
}

/**
* Get a new Client instance.
*
* @param \React\EventLoop\LoopInterface $loop
*
* @return \Vinelab\Minion\Client
*/
public function newClient()
public function newClient(LoopInterface $loop = null)
{
return new Client($this->getConfig('realm'), $this->getRegisteredProviders());
return new Client($this->getConfig('realm'), $this->getRegisteredProviders(), $loop);
}

/**
Expand Down
0