10. Event Emitter ExampleEvent Emitter Example
<?php
include('../../src/Carica/Io/Loader.php');
CaricaIoLoader::register();
$server = new CaricaIoNetworkServer();
$server->events()->on(
'connection',
function ($stream) {
...
}
);
$server->listen(8080);
CaricaIoEventLoopFactory::run();
11. CallbacksCallbacks
● list of handlers for one event
$foo = new stdClass();
$foo->literal = '';
$callbacks = new CaricaIoCallbacks();
$callbacks
->add(
function () use ($foo) {
$foo->literal .= 'Hello ';
}
)
->add(
function () use ($foo) {
$foo->literal .= 'World!';
}
);
$callbacks();
echo $foo->literal;
12. Deferred/PromiseDeferred/Promise
● „An object that acts as a proxy for a result that is initially unknown, usually
because the computation of its value is yet incomplete.“ (Wikipedia)
● http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/
● jQuery $.Deferred
● ReactPHP/Promise
● https://github.com/reactphp/promise/
● CaricaIoPromise