Initial commit
This commit is contained in:
33
examples/local.php
Normal file
33
examples/local.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
use NoccyLabs\React\CommandBus\CommandBus;
|
||||
use NoccyLabs\React\CommandBus\CommandRegistry;
|
||||
use NoccyLabs\React\CommandBus\Context;
|
||||
use React\EventLoop\Loop;
|
||||
use React\Promise\Promise;
|
||||
|
||||
$commands = new CommandRegistry();
|
||||
$commands->register("hello", function (Context $context) {
|
||||
return new Promise(function (callable $resolve) use ($context) {
|
||||
Loop::addTimer(1, function () use ($context, $resolve) {
|
||||
$resolve("Hello, {$context->name}");
|
||||
});
|
||||
});
|
||||
});
|
||||
$commands->register("hello2", function (Context $context) {
|
||||
return "Hello2, {$context->name}";
|
||||
});
|
||||
|
||||
$bus = new CommandBus($commands);
|
||||
|
||||
$bus->execute('hello', ['name'=>'Bob'])
|
||||
->then(function ($result) {
|
||||
var_dump($result);
|
||||
});
|
||||
|
||||
$bus->execute('hello2', ['name'=>'Bob'])
|
||||
->then(function ($result) {
|
||||
var_dump($result);
|
||||
});
|
Reference in New Issue
Block a user