Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yadaiio committed Feb 9, 2024
1 parent 63fad80 commit 8cab698
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ as defined in [RFC 6763](https://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
<?php

require __DIR__ . '/vendor/autoload.php';

$factory = new Factory();
$resolver = $factory->createResolver();

$resolver->lookup('hostname.local')->then(function ($ip) {
echo 'Found: ' . $ip . PHP_EOL;
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
```

See also the [examples](examples).
See also the [examples](examples/).

## Usage

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

```php
<?php

require __DIR__ . '/vendor/autoload.php';

$resolver->lookup($hostname)->then(
function ($ip) {
// IP successfully resolved
Expand All @@ -105,6 +115,10 @@ you should look into also using [clue/reactphp-block](https://github.com/clue/re
The resulting blocking code could look something like this:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Clue\React\Block;

$factory = new Factory();
Expand All @@ -123,6 +137,10 @@ try {
Similarly, you can also process multiple lookups concurrently and await an array of results:

```php
<?php

require __DIR__ . '/vendor/autoload.php';

$promises = array(
$resolver->lookup('first.local'),
$resolver->lookup('second.local'),
Expand Down

0 comments on commit 8cab698

Please sign in to comment.