-
Notifications
You must be signed in to change notification settings - Fork 2k
/
StreamSubscriptionHandleExtensions.cs
189 lines (179 loc) · 13.2 KB
/
StreamSubscriptionHandleExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Orleans.Streams
{
public static class StreamSubscriptionHandleExtensions
{
private static readonly Func<Exception, Task> DefaultOnError = _ => Task.CompletedTask;
private static readonly Func<Task> DefaultOnCompleted = () => Task.CompletedTask;
/// <summary>
/// Resumes consumption of a stream using delegates.
/// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
/// handler methods instead of requiring an instance of IAsyncObserver.
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="onErrorAsync">Delegate that is called for IAsyncObserver.OnErrorAsync.</param>
/// <param name="onCompletedAsync">Delegate that is called for IAsyncObserver.OnCompletedAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<T, StreamSequenceToken, Task> onNextAsync,
Func<Exception, Task> onErrorAsync,
Func<Task> onCompletedAsync,
StreamSequenceToken token = null)
{
var genericObserver = new GenericAsyncObserver<T>(onNextAsync, onErrorAsync, onCompletedAsync);
return handle.ResumeAsync(genericObserver, token);
}
/// <summary>
/// Resumes consumption of a stream using delegates.
/// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
/// handler methods instead of requiring an instance of IAsyncObserver.
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="onErrorAsync">Delegate that is called for IAsyncObserver.OnErrorAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<T, StreamSequenceToken, Task> onNextAsync,
Func<Exception, Task> onErrorAsync,
StreamSequenceToken token = null)
{
return handle.ResumeAsync(onNextAsync, onErrorAsync, DefaultOnCompleted, token);
}
/// <summary>
/// Resumes consumption of a stream using delegates.
/// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
/// handler methods instead of requiring an instance of IAsyncObserver.
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="onCompletedAsync">Delegate that is called for IAsyncObserver.OnCompletedAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<T, StreamSequenceToken, Task> onNextAsync,
Func<Task> onCompletedAsync,
StreamSequenceToken token = null)
{
return handle.ResumeAsync(onNextAsync, DefaultOnError, onCompletedAsync, token);
}
/// <summary>
/// <exception cref="ArgumentException">Thrown if the supplied stream filter function is not suitable.
/// Usually this is because it is not a static method. </exception>
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<T, StreamSequenceToken, Task> onNextAsync,
StreamSequenceToken token = null)
{
return handle.ResumeAsync(onNextAsync, DefaultOnError, DefaultOnCompleted, token);
}
/// <summary>
/// Resumes consumption of a stream using delegates.
/// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
/// handler methods instead of requiring an instance of IAsyncBatchObserver.
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="onErrorAsync">Delegate that is called for IAsyncObserver.OnErrorAsync.</param>
/// <param name="onCompletedAsync">Delegate that is called for IAsyncObserver.OnCompletedAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<IList<SequentialItem<T>>, Task> onNextAsync,
Func<Exception, Task> onErrorAsync,
Func<Task> onCompletedAsync,
StreamSequenceToken token = null)
{
var genericObserver = new GenericAsyncBatchObserver<T>(onNextAsync, onErrorAsync, onCompletedAsync);
return handle.ResumeAsync(genericObserver, token);
}
/// <summary>
/// Resumes consumption of a stream using delegates.
/// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
/// handler methods instead of requiring an instance of IAsyncBatchObserver.
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="onErrorAsync">Delegate that is called for IAsyncObserver.OnErrorAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<IList<SequentialItem<T>>, Task> onNextAsync,
Func<Exception, Task> onErrorAsync,
StreamSequenceToken token = null)
{
return handle.ResumeAsync(onNextAsync, onErrorAsync, DefaultOnCompleted, token);
}
/// <summary>
/// Resumes consumption of a stream using delegates.
/// This method is a helper for the StreamSubscriptionHandle.ResumeAsync allowing the subscribing class to inline the
/// handler methods instead of requiring an instance of IAsyncBatchObserver.
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="onCompletedAsync">Delegate that is called for IAsyncObserver.OnCompletedAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<IList<SequentialItem<T>>, Task> onNextAsync,
Func<Task> onCompletedAsync,
StreamSequenceToken token = null)
{
return handle.ResumeAsync(onNextAsync, DefaultOnError, onCompletedAsync, token);
}
/// <summary>
/// <exception cref="ArgumentException">Thrown if the supplied stream filter function is not suitable.
/// Usually this is because it is not a static method. </exception>
/// </summary>
/// <typeparam name="T">The type of object produced by the observable.</typeparam>
/// <param name="handle">The subscription handle.</param>
/// <param name="onNextAsync">Delegate that is called for IAsyncObserver.OnNextAsync.</param>
/// <param name="token">The stream sequence to be used as an offset to start the subscription from.</param>
/// <returns>A promise for a StreamSubscriptionHandle that represents the subscription.
/// The consumer may unsubscribe by using this handle.
/// The subscription remains active for as long as it is not explicitly unsubscribed.
/// </returns>
public static Task<StreamSubscriptionHandle<T>> ResumeAsync<T>(this StreamSubscriptionHandle<T> handle,
Func<IList<SequentialItem<T>>, Task> onNextAsync,
StreamSequenceToken token = null)
{
return handle.ResumeAsync(onNextAsync, DefaultOnError, DefaultOnCompleted, token);
}
}
}