Skip to content

Commit eeacfdb

Browse files
committed
add some doc for watcher
1 parent 2aadaba commit eeacfdb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Watcher.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ public enum WatchEventType
2222

2323
public class Watcher<T> : IDisposable
2424
{
25+
/// <summary>
26+
/// indicate if the watch object is alive
27+
/// </summary>
2528
public bool Watching { get; private set; }
2629

2730
private readonly CancellationTokenSource _cts;
2831
private readonly StreamReader _streamReader;
2932

30-
public Watcher(StreamReader streamReader, Action<WatchEventType, T> onEvent, Action<Exception> onError)
33+
internal Watcher(StreamReader streamReader, Action<WatchEventType, T> onEvent, Action<Exception> onError)
3134
{
3235
_streamReader = streamReader;
3336
OnEvent += onEvent;
@@ -82,7 +85,14 @@ public void Dispose()
8285
_streamReader.Dispose();
8386
}
8487

88+
/// <summary>
89+
/// add/remove callbacks when any event raised from api server
90+
/// </summary>
8591
public event Action<WatchEventType, T> OnEvent;
92+
93+
/// <summary>
94+
/// add/remove callbacks when any exception was caught during watching
95+
/// </summary>
8696
public event Action<Exception> OnError;
8797

8898
public class WatchEvent
@@ -95,6 +105,14 @@ public class WatchEvent
95105

96106
public static class WatcherExt
97107
{
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>
98116
public static Watcher<T> Watch<T>(this HttpOperationResponse response,
99117
Action<WatchEventType, T> onEvent,
100118
Action<Exception> onError = null)
@@ -107,6 +125,14 @@ public static Watcher<T> Watch<T>(this HttpOperationResponse response,
107125
return new Watcher<T>(content.StreamReader, onEvent, onError);
108126
}
109127

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>
110136
public static Watcher<T> Watch<T>(this HttpOperationResponse<T> response,
111137
Action<WatchEventType, T> onEvent,
112138
Action<Exception> onError = null)

src/WatcherDelegatingHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
namespace k8s
88
{
9+
/// <summary>
10+
/// This HttpDelegatingHandler is to rewrite the response and return first line to autorest client
11+
/// then use WatchExt to create a watch object which interact with the replaced http response to get watch works.
12+
/// </summary>
913
internal class WatcherDelegatingHandler : DelegatingHandler
1014
{
1115
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,

0 commit comments

Comments
 (0)