Skip to content

Commit 9850089

Browse files
committed
Give eetcd_watcher behaviour example in README.md
1 parent b000c6e commit 9850089

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+
-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+
281330
Test
282331
-----
283332

0 commit comments

Comments
 (0)