-
Notifications
You must be signed in to change notification settings - Fork 7
Simplify usage by supporting new default loop #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,15 +34,13 @@ as defined in [RFC 6763](http://tools.ietf.org/html/rfc6763). | |
Once [installed](#install), you can use the following code to look up the address of a local domain name: | ||
|
||
```php | ||
$loop = React\EventLoop\Factory::create(); | ||
$factory = new Factory($loop); | ||
$factory = new Factory(); | ||
$resolver = $factory->createResolver(); | ||
|
||
$resolver->lookup('hostname.local')->then(function ($ip) { | ||
echo 'Found: ' . $ip . PHP_EOL; | ||
}); | ||
|
||
$loop->run(); | ||
``` | ||
|
||
See also the [examples](examples). | ||
|
@@ -52,11 +50,9 @@ See also the [examples](examples). | |
### Factory | ||
|
||
The `Factory` is responsible for creating your [`Resolver`](#resolver) instance. | ||
It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage). | ||
|
||
```php | ||
$loop = React\EventLoop\Factory::create(); | ||
$factory = new Factory($loop); | ||
$factory = new Factory(); | ||
``` | ||
|
||
#### createResolver() | ||
|
@@ -106,14 +102,13 @@ The resulting blocking code could look something like this: | |
```php | ||
use Clue\React\Block; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
$factory = new Factory($loop); | ||
$factory = new Factory(); | ||
$resolver = $factory->createResolver(); | ||
|
||
$promise = $resolver->lookup('me.local'); | ||
|
||
try { | ||
$ip = Block\await($promise, $loop); | ||
$ip = Block\await($promise); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not supported by underlying |
||
// IP successfully resolved | ||
} catch (Exception $e) { | ||
// an error occured while performing the request | ||
|
@@ -128,7 +123,7 @@ $promises = array( | |
$resolver->lookup('second.local'), | ||
); | ||
|
||
$ips = Block\awaitAll($promises, $loop); | ||
$ips = Block\awaitAll($promises); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not supported, see above. |
||
``` | ||
|
||
Please refer to [clue/reactphp-block](https://github.com/clue/reactphp-block#readme) for more details. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
|
||
$name = isset($argv[1]) ? $argv[1] : 'me.local'; | ||
|
||
$loop = React\EventLoop\Factory::create(); | ||
$factory = new Clue\React\Mdns\Factory($loop); | ||
$factory = new Clue\React\Mdns\Factory(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, but example still references a leftover |
||
$mdns = $factory->createResolver(); | ||
|
||
$mdns->resolve($name)->then('e', 'e'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but could use some additional docs?