Skip to content

Commit 0970cd8

Browse files
committed
Improve documentation
1 parent 63fad80 commit 0970cd8

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,21 @@ as defined in [RFC 6763](https://tools.ietf.org/html/rfc6763).
3434
Once [installed](#install), you can use the following code to look up the address of a local domain name:
3535

3636
```php
37-
$factory = new Factory();
37+
<?php
38+
39+
require __DIR__ . '/vendor/autoload.php';
40+
41+
$factory = new Clue\React\Mdns\Factory();
3842
$resolver = $factory->createResolver();
3943

40-
$resolver->lookup('hostname.local')->then(function ($ip) {
41-
echo 'Found: ' . $ip . PHP_EOL;
44+
$resolver->resolve('hostname.local')->then(function ($ip) {
45+
echo 'Found: ' . $ip . PHP_EOL;
46+
}, function (Exception $e) {
47+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
4248
});
4349
```
4450

45-
See also the [examples](examples).
51+
See also the [examples](examples/).
4652

4753
## Usage
4854

@@ -83,7 +89,7 @@ Sending queries uses a [Promise](https://github.com/reactphp/promise)-based inte
8389
(i.e. either successfully resolved or rejected with an error):
8490

8591
```php
86-
$resolver->lookup($hostname)->then(
92+
$resolver->resolve($hostname)->then(
8793
function ($ip) {
8894
// IP successfully resolved
8995
},
@@ -105,12 +111,16 @@ you should look into also using [clue/reactphp-block](https://github.com/clue/re
105111
The resulting blocking code could look something like this:
106112

107113
```php
114+
<?php
115+
116+
require __DIR__ . '/vendor/autoload.php';
117+
108118
use Clue\React\Block;
109119

110-
$factory = new Factory();
120+
$factory = new Clue\React\Mdns\Factory();
111121
$resolver = $factory->createResolver();
112122

113-
$promise = $resolver->lookup('me.local');
123+
$promise = $resolver->resolve('me.local');
114124

115125
try {
116126
$ip = Block\await($promise, $loop);
@@ -124,8 +134,8 @@ Similarly, you can also process multiple lookups concurrently and await an array
124134

125135
```php
126136
$promises = array(
127-
$resolver->lookup('first.local'),
128-
$resolver->lookup('second.local'),
137+
$resolver->resolve('first.local'),
138+
$resolver->resolve('second.local'),
129139
);
130140

131141
$ips = Block\awaitAll($promises, $loop);

examples/lookup.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
$factory = new Clue\React\Mdns\Factory();
88
$mdns = $factory->createResolver();
99

10-
$mdns->resolve($name)->then('e', 'e');
11-
12-
function e($v) {
13-
echo $v . PHP_EOL;
14-
}
10+
$mdns->resolve($name)->then(function ($ip) {
11+
echo 'Found: ' . $ip . PHP_EOL;
12+
}, function (Exception $e) {
13+
echo 'Error: ' . $e->getMessage() . PHP_EOL;
14+
});

0 commit comments

Comments
 (0)