Skip to content

Instantly share code, notes, and snippets.

View jsor's full-sized avatar
💨

Jan Sorgalla jsor

💨
View GitHub Profile
<?php
use Predis\Async\Client as PredisClient;
function save(PredisClient $redis)
{
$deferred = new Deferred();
$tx = $redis->multiExec();
class RedisMonitor
{
private $redis;
public function __construct(Client $redis)
{
$this->redis = $redis;
}
public function __invoke()
@jsor
jsor / Connection.php
Last active April 27, 2018 07:12
Async MySQL Client
<?php
namespace Jsor\MysqlAsync;
use React\EventLoop\LoopInterface;
use React\Promise\Deferred;
class Connection
{
private $loop;
@jsor
jsor / gist:4109766
Created November 19, 2012 09:14 — forked from igorw/gist:4108347
React v0.2.4 release notes

React v0.2.4 is more awesome

DNS promises

This release has two major improvements. The first one is that react/dns is now using a promise based API. In case you missed it, react/promise is a PHP library for promises. Take a look at the README and familiarize yourself with it, as it will be used by many libs in the react ecosystem, including core.

The previous API was:

$dns->resolve('igor.io', function ($ip) {

echo "Yay, the IP is $ip.\n";

<?php
namespace React\Stomp;
class Acknowledgement
{
private $client;
private $messageId;
private $subscriptionId;
$d1 = new Deferred();
$d2 = new Deferred();
When::all(
array('abc' => $d1->promise(), 1 => $d2->promise()),
$mock
);
$d2->resolve(2);
$d1->resolve(1);
<?php
namespace React\Whois;
use Promise\Deferred as Deferred;
use React\Curry\Util as Curry;
use React\Dns\Resolver\Resolver;
class Client
{
Promise::when(array($promise1, $promise2))
->then(function($resultOfPromise1, $resultOfPromise2) {
});
// VS.
Promise::when(array($promise1, $promise2))
->then(function(array $resultsOfPromisesAsArray) {
});
<?php
class ConnectionEventSubscriber implements EventSubscriber
{
public function getSubscribedEvents()
{
return array(
Events::postConnect
);
}
$fp = fopen("data.UTF-8.xml", "r");
stream_filter_prepend($fp, "convert.iconv.UTF-8/ISO-8859-1");
$converted = '';
while (!feof($fp)) {
$converted .= fread($fp, 1000);
}