Skip to content

Instantly share code, notes, and snippets.

@igorw
Last active December 25, 2015 19:49
Show Gist options
  • Save igorw/7030479 to your computer and use it in GitHub Desktop.
Save igorw/7030479 to your computer and use it in GitHub Desktop.
alternate react API
<?php
React\Socket\connect('igor.io')
->then(function ($conn) {
$conn->write('foo');
$conn->end();
});
React\DNS\resolve('igor.io')
->then(function ($host) {
echo $host;
});
React\Http\request('igor.io')
->then(function ($request, $response) {
$request->pipe(...);
});
// I/O
$stream->read(512)
->then(function ($data) {
echo $data;
});
// generators
$parser = new Parser();
$parser->onFoo($fooHandler);
$scheduler->spawn(function ($parser) {
$conn = (yield React\Socket\connect('igor.io'));
do {
$chunk = (yield $conn->read(512));
$parser->feed($chunk);
} while ($parser->isReading());
}, $parser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment