@@ -22,12 +22,15 @@ public enum WatchEventType
22
22
23
23
public class Watcher < T > : IDisposable
24
24
{
25
+ /// <summary>
26
+ /// indicate if the watch object is alive
27
+ /// </summary>
25
28
public bool Watching { get ; private set ; }
26
29
27
30
private readonly CancellationTokenSource _cts ;
28
31
private readonly StreamReader _streamReader ;
29
32
30
- public Watcher ( StreamReader streamReader , Action < WatchEventType , T > onEvent , Action < Exception > onError )
33
+ internal Watcher ( StreamReader streamReader , Action < WatchEventType , T > onEvent , Action < Exception > onError )
31
34
{
32
35
_streamReader = streamReader ;
33
36
OnEvent += onEvent ;
@@ -82,7 +85,14 @@ public void Dispose()
82
85
_streamReader . Dispose ( ) ;
83
86
}
84
87
88
+ /// <summary>
89
+ /// add/remove callbacks when any event raised from api server
90
+ /// </summary>
85
91
public event Action < WatchEventType , T > OnEvent ;
92
+
93
+ /// <summary>
94
+ /// add/remove callbacks when any exception was caught during watching
95
+ /// </summary>
86
96
public event Action < Exception > OnError ;
87
97
88
98
public class WatchEvent
@@ -95,6 +105,14 @@ public class WatchEvent
95
105
96
106
public static class WatcherExt
97
107
{
108
+ /// <summary>
109
+ /// create a watch object from a call to api server with watch=true
110
+ /// </summary>
111
+ /// <typeparam name="T">type of the event object</typeparam>
112
+ /// <param name="response">the api response</param>
113
+ /// <param name="onEvent">a callback when any event raised from api server</param>
114
+ /// <param name="onError">a callbak when any exception was caught during watching</param>
115
+ /// <returns>a watch object</returns>
98
116
public static Watcher < T > Watch < T > ( this HttpOperationResponse response ,
99
117
Action < WatchEventType , T > onEvent ,
100
118
Action < Exception > onError = null )
@@ -107,6 +125,14 @@ public static Watcher<T> Watch<T>(this HttpOperationResponse response,
107
125
return new Watcher < T > ( content . StreamReader , onEvent , onError ) ;
108
126
}
109
127
128
+ /// <summary>
129
+ /// create a watch object from a call to api server with watch=true
130
+ /// </summary>
131
+ /// <typeparam name="T">type of the event object</typeparam>
132
+ /// <param name="response">the api response</param>
133
+ /// <param name="onEvent">a callback when any event raised from api server</param>
134
+ /// <param name="onError">a callbak when any exception was caught during watching</param>
135
+ /// <returns>a watch object</returns>
110
136
public static Watcher < T > Watch < T > ( this HttpOperationResponse < T > response ,
111
137
Action < WatchEventType , T > onEvent ,
112
138
Action < Exception > onError = null )
0 commit comments