@@ -19,6 +19,8 @@ as defined in [RFC 6763](http://tools.ietf.org/html/rfc6763).
19
19
* [ Factory] ( #factory )
20
20
* [ createResolver()] ( #createresolver )
21
21
* [ Resolver] ( #resolver )
22
+ * [ Promises] ( #promises )
23
+ * [ Blocking] ( #blocking )
22
24
* [ Install] ( #install )
23
25
* [ License] ( #license )
24
26
@@ -69,6 +71,8 @@ The [`Factory`](#factory) creates instances of the `React\Dns\Resolver\Resolver`
69
71
While React's * normal* DNS resolver uses unicast UDP messages (and TCP streams) to query a given nameserver,
70
72
this resolver instance uses multicast UDP messages to query all reachable hosts in your network.
71
73
74
+ #### Promises
75
+
72
76
Sending queries is async (non-blocking), so you can actually send multiple DNS queries in parallel.
73
77
The mDNS hosts will respond to each DNS query message with a DNS response message. The order is not guaranteed.
74
78
Sending 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(
87
91
88
92
Please refer to the [ DNS documentation] ( https://github.com/reactphp/dns#readme ) for more details.
89
93
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
+
90
133
## Install
91
134
92
135
The 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