@@ -278,6 +278,55 @@ We can use a single stream for multiplex watches, see [example](/test/eetcd_watc
278
278
- ` Active ` is normal connection.
279
279
- ` Freeze ` is a broken connection who try to reconnect after ` ReconnectSecond ` .
280
280
281
+
282
+ ##### Watcher - Watcher which use ` eetcd_watcher ` behaviour
283
+
284
+ ``` erlang
285
+ -module (eetcd_watcher_example ).
286
+
287
+ -include_lib (" eetcd/include/eetcd.hrl" ).
288
+ -behaviour (eetcd_watcher ).
289
+
290
+ -export ([ start_link /2 , watch /1 , unwatch /0 , stop /0 ]).
291
+
292
+ -export ([ handle_watch_events /1 , handle_unwatch_response /2 ]).
293
+
294
+
295
+ -type options () :: eetcd_watcher :options ().
296
+
297
+ -type response () :: eetcd_watcher :response ().
298
+
299
+ -type event () :: eetcd_watcher :event ().
300
+
301
+ -type watch_req () :: eetcd_watcher :watch_req ().
302
+
303
+ -spec watch (watch_req ()) -> ok .
304
+ watch (WatchReq ) ->
305
+ eetcd_watcher :watch (? MODULE , WatchReq ).
306
+
307
+ -spec unwatch () -> ok .
308
+ unwatch () ->
309
+ eetcd_watcher :unwatch (? MODULE ).
310
+
311
+ -spec start_link (name (), options ()) -> ok .
312
+ start_link (Client , Options ) ->
313
+ eetcd_watcher :start_link (? MODULE , Client , Options ).
314
+
315
+ -spec stop () -> ok .
316
+ stop () ->
317
+ eetcd_watcher :stop (? MODULE ).
318
+
319
+ -spec handle_watch_events ([event ()]) -> ok .
320
+ handle_watch_events (Events ) ->
321
+ % % Handle watch events ...
322
+ ok .
323
+
324
+ -spec handle_unwatch ([response ()], [event ()]) -> ok .
325
+ handle_unwatch (Responses , Events ) ->
326
+ % % Handle unwatch response ...
327
+ ok .
328
+ ```
329
+
281
330
Test
282
331
-----
283
332
0 commit comments