-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathIServerTimer.cs
More file actions
222 lines (207 loc) · 10.7 KB
/
IServerTimer.cs
File metadata and controls
222 lines (207 loc) · 10.7 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
namespace SS.Core.ComponentInterfaces
{
/// <summary>
/// Represents a method that handles calls from timer.
/// </summary>
/// <returns>True to continue timer events. False to end the timer.</returns>
public delegate bool TimerDelegate();
/// <summary>
/// Represents a method that handles calls from timer. The method has a single input parameter for passing "state".
/// </summary>
/// <typeparam name="TState">Type of the state parameter of the method that this delegate encapsulates.</typeparam>
/// <param name="state">An object that represents the context of the timer.</param>
/// <returns>True to continue timer events. False to end the timer.</returns>
public delegate bool TimerDelegate<in TState>(TState state);
/// <summary>
/// Represents a method to be called back when a timer is stopped/removed.
/// </summary>
public delegate void TimerCleanupDelegate();
/// <summary>
/// Represents a method to be called back when a timer is stopped/removed.
/// </summary>
/// <typeparam name="TState">Type of the state parameter of the method that this delegate encapsulates.</typeparam>
/// <param name="state">An object that represents the context of the timer.</param>
public delegate void TimerCleanupDelegate<in TState>(TState state);
/// <summary>
/// Interface with methods to schedule timers that run on threads from the thread pool.
/// See <see cref="IMainloopTimer"/> for timers that run on the main loop.
/// </summary>
public interface IServerTimer : IComponentInterface
{
/// <summary>
/// Starts a timer.
/// </summary>
/// <param name="callback">The delegate that the timer should invoke.</param>
/// <param name="initialDelay">How long to wait for the first call (in milliseconds).</param>
/// <param name="interval">How long to wait between calls (in milliseconds).</param>
/// <param name="key">A key that can be used to selectively cancel timers.</param>
void SetTimer(
TimerDelegate callback,
int initialDelay,
int interval,
object? key);
/// <summary>
/// Starts a timer.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate that the timer should invoke.</param>
/// <param name="initialDelay">How long to wait for the first call (in milliseconds).</param>
/// <param name="interval">How long to wait between calls (in milliseconds).</param>
/// <param name="state">A closure argument that will get passed to the timer <paramref name="callback"/>.</param>
/// <param name="key">A key that can be used to selectively cancel timers.</param>
void SetTimer<TState>(
TimerDelegate<TState> callback,
int initialDelay,
int interval,
TState state,
object? key);
/// <summary>
/// Stops and removes a timer.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
void ClearTimer(
TimerDelegate callback,
object? key);
/// <summary>
/// Stops and removes a timer.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
/// <param name="cleanupCallback">
/// A <see cref="TimerCleanupDelegate{TState}"/> to call once for each timer that is stopped.
/// </param>
void ClearTimer(
TimerDelegate callback,
object? key,
TimerCleanupDelegate cleanupCallback);
/// <summary>
/// Stops and removes a timer.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
void ClearTimer<TState>(
TimerDelegate<TState> callback,
object? key);
/// <summary>
/// Stops and removes a timer, with a <paramref name="cleanupCallback"/> to be invoked for each timer that is stopped.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
/// <param name="cleanupCallback">
/// A <see cref="TimerCleanupDelegate{TState}"/> to call once for each timer that is stopped.
/// It will be called with the <c>parameter</c> that was provided when the timer was started.
/// </param>
void ClearTimer<TState>(
TimerDelegate<TState> callback,
object? key,
TimerCleanupDelegate<TState> cleanupCallback);
}
/// <summary>
/// Interface with methods to schedule timers that run on the main loop.
/// See <see cref="IServerTimer"/> for timers that run on threads from the thread pool.
/// </summary>
public interface IMainloopTimer : IComponentInterface
{
/// <summary>
/// Starts a timer.
/// </summary>
/// <param name="callback">The delegate that the timer should invoke.</param>
/// <param name="initialDelay">How long to wait for the first call (in milliseconds).</param>
/// <param name="interval">How long to wait between calls (in milliseconds).</param>
/// <param name="key">A key that can be used to selectively cancel timers.</param>
void SetTimer(
TimerDelegate callback,
int initialDelay,
int interval,
object? key);
/// <summary>
/// Starts a timer.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate that the timer should invoke.</param>
/// <param name="initialDelay">How long to wait for the first call (in milliseconds).</param>
/// <param name="interval">How long to wait between calls (in milliseconds).</param>
/// <param name="state">A closure argument that will get passed to the timer <paramref name="callback"/>.</param>
/// <param name="key">A key that can be used to selectively cancel timers.</param>
void SetTimer<TState>(
TimerDelegate<TState> callback,
int initialDelay,
int interval,
TState state,
object? key);
/// <summary>
/// Stops and removes timers.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
void ClearTimer(
TimerDelegate callback,
object? key);
/// <summary>
/// Stops and removes timers, with a <paramref name="cleanupCallback"/> to be invoked for each timer that is stopped.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
/// <param name="cleanupCallback">
/// A <see cref="TimerCleanupDelegate{TState}"/> to call once for each timer that is stopped.
/// </param>
void ClearTimer(
TimerDelegate callback,
object? key,
TimerCleanupDelegate cleanupCallback);
/// <summary>
/// Stops and removes timers.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
void ClearTimer<TState>(
TimerDelegate<TState> callback,
object? key);
/// <summary>
/// Stops and removes timers, with a <paramref name="cleanupCallback"/> to be invoked for each timer that is stopped.
/// </summary>
/// <typeparam name="TState">The type of parameter the <paramref name="callback"/> accepts.</typeparam>
/// <param name="callback">The delegate to clear timer(s) for.</param>
/// <param name="key">
/// Timers that match this key will be removed.
/// Use <see langword="null"/> to clear all timers associated with <paramref name="callback"/>, regardless of key.
/// </param>
/// <param name="cleanupCallback">
/// A <see cref="TimerCleanupDelegate{TState}"/> to call once for each timer that is stopped.
/// It will be called with the <typeparamref name="TState"/> that was provided when the timer was started.
/// </param>
void ClearTimer<TState>(
TimerDelegate<TState> callback,
object? key,
TimerCleanupDelegate<TState> cleanupCallback);
}
}