Updated readme, examples
This commit is contained in:
		| @@ -9,7 +9,12 @@ use React\EventLoop\Loop; | ||||
| use React\Promise\Promise; | ||||
|  | ||||
| $commands = new CommandRegistry(); | ||||
| // Register some function to call. The name here is "hello", and it will | ||||
| // receive a Context holding the call context. Any passed data will be | ||||
| // available as properties on the Context object. | ||||
| $commands->register("hello", function (Context $context) { | ||||
|     // You don't have to, but you should return a promise from your  | ||||
|     // commands. | ||||
|     return new Promise(function (callable $resolve) use ($context) { | ||||
|         Loop::addTimer(1, function () use ($context, $resolve) { | ||||
|             $resolve("Hello, {$context->name}"); | ||||
| @@ -17,17 +22,22 @@ $commands->register("hello", function (Context $context) { | ||||
|     }); | ||||
| }); | ||||
| $commands->register("hello2", function (Context $context) { | ||||
|     // Just returning the value works just fine! | ||||
|     return "Hello2, {$context->name}"; | ||||
| }); | ||||
|  | ||||
| // Create the bus | ||||
| $bus = new CommandBus($commands); | ||||
|  | ||||
| $bus->execute('hello', ['name'=>'Bob']) | ||||
| ->then(function ($result) { | ||||
|     var_dump($result); | ||||
| }); | ||||
| // And execute some commands! | ||||
| $bus->execute('hello', ['name'=>'Bob'])->then( | ||||
|     function ($result) { | ||||
|         var_dump($result); | ||||
|     } | ||||
| ); | ||||
|  | ||||
| $bus->execute('hello2', ['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