Skip to content

Commit 909cd2b

Browse files
committed
Give eetcd_watcher behaviour example in README.md
1 parent ecc8047 commit 909cd2b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,55 @@ We can use a single stream for multiplex watches, see [example](/test/eetcd_watc
278278
- `Active` is normal connection.
279279
- `Freeze` is a broken connection who try to reconnect after `ReconnectSecond`.
280280

281+
282+
##### Watcher - Watcher which use `eetcd_watcher` behaviour
283+
284+
``` erlang
285+
-module(eetcd_watcher_example).
286+
287+
-behaviour(eetcd_watcher).
288+
289+
-export([ start/2, watch/1, unwatch/0, stop/0 ]).
290+
291+
-export([ handle_watch_events/1, handle_unwatch_response/2 ]).
292+
293+
-type client_name() :: eetcd_watcher:client_name().
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(client_name(), options()) -> ok.
312+
start(ClientName, Options) ->
313+
eetcd_watcher:start(?MODULE, ClientName, ?MODULE, 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([response()], [event()]) -> ok.
325+
handle_unwatch_response(Responses, Events) ->
326+
%% Handle unwatch response ...
327+
ok.
328+
```
329+
281330
Test
282331
-----
283332

0 commit comments

Comments
 (0)