@@ -19,6 +19,8 @@ as defined in [RFC 6763](http://tools.ietf.org/html/rfc6763).
1919 * [ Factory] ( #factory )
2020 * [ createResolver()] ( #createresolver )
2121 * [ Resolver] ( #resolver )
22+ * [ Promises] ( #promises )
23+ * [ Blocking] ( #blocking )
2224* [ Install] ( #install )
2325* [ License] ( #license )
2426
@@ -69,6 +71,8 @@ The [`Factory`](#factory) creates instances of the `React\Dns\Resolver\Resolver`
6971While React's * normal* DNS resolver uses unicast UDP messages (and TCP streams) to query a given nameserver,
7072this resolver instance uses multicast UDP messages to query all reachable hosts in your network.
7173
74+ #### Promises
75+
7276Sending queries is async (non-blocking), so you can actually send multiple DNS queries in parallel.
7377The mDNS hosts will respond to each DNS query message with a DNS response message. The order is not guaranteed.
7478Sending queries uses a [ Promise] ( https://github.com/reactphp/promise ) -based interface that makes it easy to react to when a query is * fulfilled*
@@ -87,6 +91,45 @@ $resolver->lookup($hostname)->then(
8791
8892Please refer to the [ DNS documentation] ( https://github.com/reactphp/dns#readme ) for more details.
8993
94+ #### Blocking
95+
96+ As stated above, this library provides you a powerful, async API by default.
97+
98+ If, however, you want to integrate this into your traditional, blocking environment,
99+ you should look into also using [ clue/block-react] ( https://github.com/clue/php-block-react ) .
100+
101+ The resulting blocking code could look something like this:
102+
103+ ``` php
104+ use Clue\React\Block;
105+
106+ $loop = React\EventLoop\Factory::create();
107+ $factory = new Factory($loop);
108+ $resolver = $factory->createResolver();
109+
110+ $promise = $resolver->lookup('me.local');
111+
112+ try {
113+ $ip = Block\await($promise, $loop);
114+ // IP successfully resolved
115+ } catch (Exception $e) {
116+ // an error occured while performing the request
117+ }
118+ ```
119+
120+ Similarly, you can also process multiple lookups concurrently and await an array of results:
121+
122+ ``` php
123+ $promises = array(
124+ $resolver->lookup('first.local'),
125+ $resolver->lookup('second.local'),
126+ );
127+
128+ $ips = Block\awaitAll($promises, $loop);
129+ ```
130+
131+ Please refer to [ clue/block-react] ( https://github.com/clue/php-block-react#readme ) for more details.
132+
90133## Install
91134
92135The recommended way to install this library is [ through composer] ( http://getcomposer.org ) . [ New to composer?] ( http://getcomposer.org/doc/00-intro.md )
0 commit comments