Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Time.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 using System.Collections.Generic;
4 using System.Reactive.Concurrency;
5
6 namespace System.Reactive.Linq
7 {
8 public static partial class Observable
9 {
10 #region + Buffer +
11
12 #region TimeSpan only
13
14 /// <summary>
15 /// Projects each element of an observable sequence into consecutive non-overlapping buffers which are produced based on timing information.
16 /// </summary>
17 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
18 /// <param name="source">Source sequence to produce buffers over.</param>
19 /// <param name="timeSpan">Length of each buffer.</param>
20 /// <returns>An observable sequence of buffers.</returns>
21 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
22 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
23 /// <remarks>
24 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create buffers as fast as it can.
25 /// Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced
26 /// by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.
27 /// </remarks>
28 public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan)
29 {
30 if (source == null)
31 throw new ArgumentNullException("source");
32 if (timeSpan < TimeSpan.Zero)
33 throw new ArgumentOutOfRangeException("timeSpan");
34
35 return s_impl.Buffer<TSource>(source, timeSpan);
36 }
37
38 /// <summary>
39 /// Projects each element of an observable sequence into consecutive non-overlapping buffers which are produced based on timing information, using the specified scheduler to run timers.
40 /// </summary>
41 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
42 /// <param name="source">Source sequence to produce buffers over.</param>
43 /// <param name="timeSpan">Length of each buffer.</param>
44 /// <param name="scheduler">Scheduler to run buffering timers on.</param>
45 /// <returns>An observable sequence of buffers.</returns>
46 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
47 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
48 /// <remarks>
49 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create buffers as fast as it can.
50 /// Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced
51 /// by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.
52 /// </remarks>
53 public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, IScheduler scheduler)
54 {
55 if (source == null)
56 throw new ArgumentNullException("source");
57 if (timeSpan < TimeSpan.Zero)
58 throw new ArgumentOutOfRangeException("timeSpan");
59 if (scheduler == null)
60 throw new ArgumentNullException("scheduler");
61
62 return s_impl.Buffer<TSource>(source, timeSpan, scheduler);
63 }
64
65 /// <summary>
66 /// Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.
67 /// </summary>
68 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
69 /// <param name="source">Source sequence to produce buffers over.</param>
70 /// <param name="timeSpan">Length of each buffer.</param>
71 /// <param name="timeShift">Interval between creation of consecutive buffers.</param>
72 /// <returns>An observable sequence of buffers.</returns>
73 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
74 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> or <paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
75 /// <remarks>
76 /// <para>
77 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create buffers with minimum duration
78 /// length. However, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the
79 /// current buffer may not execute immediately, despite the TimeSpan.Zero due time.
80 /// </para>
81 /// <para>
82 /// Specifying a TimeSpan.Zero value for <paramref name="timeShift"/> is not recommended but supported, causing the scheduler to create buffers as fast as it can.
83 /// However, this doesn't mean all buffers will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler,
84 /// where the action to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.
85 /// </para>
86 /// </remarks>
87 public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift)
88 {
89 if (source == null)
90 throw new ArgumentNullException("source");
91 if (timeSpan < TimeSpan.Zero)
92 throw new ArgumentOutOfRangeException("timeSpan");
93 if (timeShift < TimeSpan.Zero)
94 throw new ArgumentOutOfRangeException("timeShift");
95
96 return s_impl.Buffer<TSource>(source, timeSpan, timeShift);
97 }
98
99 /// <summary>
100 /// Projects each element of an observable sequence into zero or more buffers which are produced based on timing information, using the specified scheduler to run timers.
101 /// </summary>
102 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
103 /// <param name="source">Source sequence to produce buffers over.</param>
104 /// <param name="timeSpan">Length of each buffer.</param>
105 /// <param name="timeShift">Interval between creation of consecutive buffers.</param>
106 /// <param name="scheduler">Scheduler to run buffering timers on.</param>
107 /// <returns>An observable sequence of buffers.</returns>
108 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
109 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> or <paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
110 /// <remarks>
111 /// <para>
112 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create buffers with minimum duration
113 /// length. However, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the
114 /// current buffer may not execute immediately, despite the TimeSpan.Zero due time.
115 /// </para>
116 /// <para>
117 /// Specifying a TimeSpan.Zero value for <paramref name="timeShift"/> is not recommended but supported, causing the scheduler to create buffers as fast as it can.
118 /// However, this doesn't mean all buffers will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler,
119 /// where the action to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.
120 /// </para>
121 /// </remarks>
122 public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift, IScheduler scheduler)
123 {
124 if (source == null)
125 throw new ArgumentNullException("source");
126 if (timeSpan < TimeSpan.Zero)
127 throw new ArgumentOutOfRangeException("timeSpan");
128 if (timeShift < TimeSpan.Zero)
129 throw new ArgumentOutOfRangeException("timeShift");
130 if (scheduler == null)
131 throw new ArgumentNullException("scheduler");
132
133 return s_impl.Buffer<TSource>(source, timeSpan, timeShift, scheduler);
134 }
135
136 #endregion
137
138 #region TimeSpan + int
139
140 /// <summary>
141 /// Projects each element of an observable sequence into a buffer that's sent out when either it's full or a given amount of time has elapsed.
142 /// A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.
143 /// </summary>
144 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
145 /// <param name="source">Source sequence to produce buffers over.</param>
146 /// <param name="timeSpan">Maximum time length of a window.</param>
147 /// <param name="count">Maximum element count of a window.</param>
148 /// <returns>An observable sequence of buffers.</returns>
149 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
150 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero. -or- <paramref name="count"/> is less than or equal to zero.</exception>
151 /// <remarks>
152 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create buffers as fast as it can.
153 /// Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced
154 /// by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.
155 /// </remarks>
156 public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count)
157 {
158 if (source == null)
159 throw new ArgumentNullException("source");
160 if (timeSpan < TimeSpan.Zero)
161 throw new ArgumentOutOfRangeException("timeSpan");
162 if (count <= 0)
163 throw new ArgumentOutOfRangeException("count");
164
165 return s_impl.Buffer<TSource>(source, timeSpan, count);
166 }
167
168 /// <summary>
169 /// Projects each element of an observable sequence into a buffer that's sent out when either it's full or a given amount of time has elapsed, using the specified scheduler to run timers.
170 /// A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.
171 /// </summary>
172 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>
173 /// <param name="source">Source sequence to produce buffers over.</param>
174 /// <param name="timeSpan">Maximum time length of a buffer.</param>
175 /// <param name="count">Maximum element count of a buffer.</param>
176 /// <param name="scheduler">Scheduler to run buffering timers on.</param>
177 /// <returns>An observable sequence of buffers.</returns>
178 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
179 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero. -or- <paramref name="count"/> is less than or equal to zero.</exception>
180 /// <remarks>
181 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create buffers as fast as it can.
182 /// Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced
183 /// by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.
184 /// </remarks>
185 public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count, IScheduler scheduler)
186 {
187 if (source == null)
188 throw new ArgumentNullException("source");
189 if (timeSpan < TimeSpan.Zero)
190 throw new ArgumentOutOfRangeException("timeSpan");
191 if (count <= 0)
192 throw new ArgumentOutOfRangeException("count");
193 if (scheduler == null)
194 throw new ArgumentNullException("scheduler");
195
196 return s_impl.Buffer<TSource>(source, timeSpan, count, scheduler);
197 }
198
199 #endregion
200
201 #endregion
202
203 #region + Delay +
204
205 #region TimeSpan
206
207 /// <summary>
208 /// Time shifts the observable sequence by the specified relative time duration.
209 /// The relative time intervals between the values are preserved.
210 /// </summary>
211 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
212 /// <param name="source">Source sequence to delay values for.</param>
213 /// <param name="dueTime">Relative time by which to shift the observable sequence. If this value is equal to TimeSpan.Zero, the scheduler will dispatch observer callbacks as soon as possible.</param>
214 /// <returns>Time-shifted sequence.</returns>
215 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
216 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
217 /// <remarks>
218 /// <para>
219 /// This operator is less efficient than <see cref="Observable.DelaySubscription{T}(IObservable{T}, TimeSpan)">DelaySubscription</see> because it records all notifications and time-delays those. This allows for immediate propagation of errors.
220 /// </para>
221 /// <para>
222 /// Observer callbacks for the resulting sequence will be run on the default scheduler. This effect is similar to using ObserveOn.
223 /// </para>
224 /// <para>
225 /// Exceptions signaled by the source sequence through an OnError callback are forwarded immediately to the result sequence. Any OnNext notifications that were in the queue at the point of the OnError callback will be dropped.
226 /// In order to delay error propagation, consider using the <see cref="Observable.Materialize">Observable.Materialize</see> and <see cref="Observable.Dematerialize">Observable.Dematerialize</see> operators, or use <see cref="Observable.DelaySubscription{T}(IObservable{T}, TimeSpan)">DelaySubscription</see>.
227 /// </para>
228 /// </remarks>
229 public static IObservable<TSource> Delay<TSource>(this IObservable<TSource> source, TimeSpan dueTime)
230 {
231 if (source == null)
232 throw new ArgumentNullException("source");
233 if (dueTime < TimeSpan.Zero)
234 throw new ArgumentOutOfRangeException("dueTime");
235
236 return s_impl.Delay<TSource>(source, dueTime);
237 }
238
239 /// <summary>
240 /// Time shifts the observable sequence by the specified relative time duration, using the specified scheduler to run timers.
241 /// The relative time intervals between the values are preserved.
242 /// </summary>
243 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
244 /// <param name="source">Source sequence to delay values for.</param>
245 /// <param name="dueTime">Relative time by which to shift the observable sequence. If this value is equal to TimeSpan.Zero, the scheduler will dispatch observer callbacks as soon as possible.</param>
246 /// <param name="scheduler">Scheduler to run the delay timers on.</param>
247 /// <returns>Time-shifted sequence.</returns>
248 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
249 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
250 /// <remarks>
251 /// <para>
252 /// This operator is less efficient than <see cref="Observable.DelaySubscription{T}(IObservable{T}, TimeSpan, IScheduler)">DelaySubscription</see> because it records all notifications and time-delays those. This allows for immediate propagation of errors.
253 /// </para>
254 /// <para>
255 /// Observer callbacks for the resulting sequence will be run on the specified scheduler. This effect is similar to using ObserveOn.
256 /// </para>
257 /// <para>
258 /// Exceptions signaled by the source sequence through an OnError callback are forwarded immediately to the result sequence. Any OnNext notifications that were in the queue at the point of the OnError callback will be dropped.
259 /// </para>
260 /// <para>
261 /// Exceptions signaled by the source sequence through an OnError callback are forwarded immediately to the result sequence. Any OnNext notifications that were in the queue at the point of the OnError callback will be dropped.
262 /// In order to delay error propagation, consider using the <see cref="Observable.Materialize">Observable.Materialize</see> and <see cref="Observable.Dematerialize">Observable.Dematerialize</see> operators, or use <see cref="Observable.DelaySubscription{T}(IObservable{T}, TimeSpan, IScheduler)">DelaySubscription</see>.
263 /// </para>
264 /// </remarks>
265 public static IObservable<TSource> Delay<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
266 {
267 if (source == null)
268 throw new ArgumentNullException("source");
269 if (dueTime < TimeSpan.Zero)
270 throw new ArgumentOutOfRangeException("dueTime");
271 if (scheduler == null)
272 throw new ArgumentNullException("scheduler");
273
274 return s_impl.Delay<TSource>(source, dueTime, scheduler);
275 }
276
277 #endregion
278
279 #region DateTimeOffset
280
281 /// <summary>
282 /// Time shifts the observable sequence to start propagating notifications at the specified absolute time.
283 /// The relative time intervals between the values are preserved.
284 /// </summary>
285 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
286 /// <param name="source">Source sequence to delay values for.</param>
287 /// <param name="dueTime">Absolute time used to shift the observable sequence; the relative time shift gets computed upon subscription. If this value is less than or equal to DateTimeOffset.UtcNow, the scheduler will dispatch observer callbacks as soon as possible.</param>
288 /// <returns>Time-shifted sequence.</returns>
289 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
290 /// <remarks>
291 /// <para>
292 /// This operator is less efficient than <see cref="Observable.DelaySubscription{T}(IObservable{T}, DateTimeOffset)">DelaySubscription</see> because it records all notifications and time-delays those. This allows for immediate propagation of errors.
293 /// </para>
294 /// <para>
295 /// Observer callbacks for the resulting sequence will be run on the default scheduler. This effect is similar to using ObserveOn.
296 /// </para>
297 /// <para>
298 /// Exceptions signaled by the source sequence through an OnError callback are forwarded immediately to the result sequence. Any OnNext notifications that were in the queue at the point of the OnError callback will be dropped.
299 /// In order to delay error propagation, consider using the <see cref="Observable.Materialize">Observable.Materialize</see> and <see cref="Observable.Dematerialize">Observable.Dematerialize</see> operators, or use <see cref="Observable.DelaySubscription{T}(IObservable{T}, DateTimeOffset)">DelaySubscription</see>.
300 /// </para>
301 /// </remarks>
302 public static IObservable<TSource> Delay<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime)
303 {
304 if (source == null)
305 throw new ArgumentNullException("source");
306
307 return s_impl.Delay<TSource>(source, dueTime);
308 }
309
310 /// <summary>
311 /// Time shifts the observable sequence to start propagating notifications at the specified absolute time, using the specified scheduler to run timers.
312 /// The relative time intervals between the values are preserved.
313 /// </summary>
314 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
315 /// <param name="source">Source sequence to delay values for.</param>
316 /// <param name="dueTime">Absolute time used to shift the observable sequence; the relative time shift gets computed upon subscription. If this value is less than or equal to DateTimeOffset.UtcNow, the scheduler will dispatch observer callbacks as soon as possible.</param>
317 /// <param name="scheduler">Scheduler to run the delay timers on.</param>
318 /// <returns>Time-shifted sequence.</returns>
319 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
320 /// <remarks>
321 /// <para>
322 /// This operator is less efficient than <see cref="Observable.DelaySubscription{T}(IObservable{T}, DateTimeOffset, IScheduler)">DelaySubscription</see> because it records all notifications and time-delays those. This allows for immediate propagation of errors.
323 /// </para>
324 /// <para>
325 /// Observer callbacks for the resulting sequence will be run on the specified scheduler. This effect is similar to using ObserveOn.
326 /// </para>
327 /// <para>
328 /// Exceptions signaled by the source sequence through an OnError callback are forwarded immediately to the result sequence. Any OnNext notifications that were in the queue at the point of the OnError callback will be dropped.
329 /// In order to delay error propagation, consider using the <see cref="Observable.Materialize">Observable.Materialize</see> and <see cref="Observable.Dematerialize">Observable.Dematerialize</see> operators, or use <see cref="Observable.DelaySubscription{T}(IObservable{T}, DateTimeOffset, IScheduler)">DelaySubscription</see>.
330 /// </para>
331 /// </remarks>
332 public static IObservable<TSource> Delay<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime, IScheduler scheduler)
333 {
334 if (source == null)
335 throw new ArgumentNullException("source");
336 if (scheduler == null)
337 throw new ArgumentNullException("scheduler");
338
339 return s_impl.Delay<TSource>(source, dueTime, scheduler);
340 }
341
342 #endregion
343
344 #region Duration selector
345
346 /// <summary>
347 /// Time shifts the observable sequence based on a delay selector function for each element.
348 /// </summary>
349 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
350 /// <typeparam name="TDelay">The type of the elements in the delay sequences used to denote the delay duration of each element in the source sequence.</typeparam>
351 /// <param name="source">Source sequence to delay values for.</param>
352 /// <param name="delayDurationSelector">Selector function to retrieve a sequence indicating the delay for each given element.</param>
353 /// <returns>Time-shifted sequence.</returns>
354 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="delayDurationSelector"/> is null.</exception>
355 public static IObservable<TSource> Delay<TSource, TDelay>(this IObservable<TSource> source, Func<TSource, IObservable<TDelay>> delayDurationSelector)
356 {
357 if (source == null)
358 throw new ArgumentNullException("source");
359 if (delayDurationSelector == null)
360 throw new ArgumentNullException("delayDurationSelector");
361
362 return s_impl.Delay<TSource, TDelay>(source, delayDurationSelector);
363 }
364
365 /// <summary>
366 /// Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
367 /// </summary>
368 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
369 /// <typeparam name="TDelay">The type of the elements in the delay sequences used to denote the delay duration of each element in the source sequence.</typeparam>
370 /// <param name="source">Source sequence to delay values for.</param>
371 /// <param name="subscriptionDelay">Sequence indicating the delay for the subscription to the source.</param>
372 /// <param name="delayDurationSelector">Selector function to retrieve a sequence indicating the delay for each given element.</param>
373 /// <returns>Time-shifted sequence.</returns>
374 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="subscriptionDelay"/> or <paramref name="delayDurationSelector"/> is null.</exception>
375 public static IObservable<TSource> Delay<TSource, TDelay>(this IObservable<TSource> source, IObservable<TDelay> subscriptionDelay, Func<TSource, IObservable<TDelay>> delayDurationSelector)
376 {
377 if (source == null)
378 throw new ArgumentNullException("source");
379 if (subscriptionDelay == null)
380 throw new ArgumentNullException("subscriptionDelay");
381 if (delayDurationSelector == null)
382 throw new ArgumentNullException("delayDurationSelector");
383
384 return s_impl.Delay<TSource, TDelay>(source, subscriptionDelay, delayDurationSelector);
385 }
386
387 #endregion
388
389 #endregion
390
391 #region + DelaySubscription +
392
393 /// <summary>
394 /// Time shifts the observable sequence by delaying the subscription with the specified relative time duration.
395 /// </summary>
396 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
397 /// <param name="source">Source sequence to delay subscription for.</param>
398 /// <param name="dueTime">Relative time shift of the subscription.</param>
399 /// <returns>Time-shifted sequence.</returns>
400 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
401 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
402 /// <remarks>
403 /// <para>
404 /// This operator is more efficient than <see cref="Observable.Delay{T}(IObservable{T}, TimeSpan)">Delay</see> but postpones all side-effects of subscription and affects error propagation timing.
405 /// </para>
406 /// <para>
407 /// The side-effects of subscribing to the source sequence will be run on the default scheduler. Observer callbacks will not be affected.
408 /// </para>
409 /// </remarks>
410 public static IObservable<TSource> DelaySubscription<TSource>(this IObservable<TSource> source, TimeSpan dueTime)
411 {
412 if (source == null)
413 throw new ArgumentNullException("source");
414 if (dueTime < TimeSpan.Zero)
415 throw new ArgumentOutOfRangeException("dueTime");
416
417 return s_impl.DelaySubscription<TSource>(source, dueTime);
418 }
419
420 /// <summary>
421 /// Time shifts the observable sequence by delaying the subscription with the specified relative time duration, using the specified scheduler to run timers.
422 /// </summary>
423 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
424 /// <param name="source">Source sequence to delay subscription for.</param>
425 /// <param name="dueTime">Relative time shift of the subscription.</param>
426 /// <param name="scheduler">Scheduler to run the subscription delay timer on.</param>
427 /// <returns>Time-shifted sequence.</returns>
428 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
429 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
430 /// <remarks>
431 /// <para>
432 /// This operator is more efficient than <see cref="Observable.Delay{T}(IObservable{T}, TimeSpan, IScheduler)">Delay</see> but postpones all side-effects of subscription and affects error propagation timing.
433 /// </para>
434 /// <para>
435 /// The side-effects of subscribing to the source sequence will be run on the specified scheduler. Observer callbacks will not be affected.
436 /// </para>
437 /// </remarks>
438 public static IObservable<TSource> DelaySubscription<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
439 {
440 if (source == null)
441 throw new ArgumentNullException("source");
442 if (dueTime < TimeSpan.Zero)
443 throw new ArgumentOutOfRangeException("dueTime");
444 if (scheduler == null)
445 throw new ArgumentNullException("scheduler");
446
447 return s_impl.DelaySubscription<TSource>(source, dueTime, scheduler);
448 }
449
450 /// <summary>
451 /// Time shifts the observable sequence by delaying the subscription to the specified absolute time.
452 /// </summary>
453 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
454 /// <param name="source">Source sequence to delay subscription for.</param>
455 /// <param name="dueTime">Absolute time to perform the subscription at.</param>
456 /// <returns>Time-shifted sequence.</returns>
457 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
458 /// <remarks>
459 /// <para>
460 /// This operator is more efficient than <see cref="Observable.Delay{T}(IObservable{T}, DateTimeOffset)">Delay</see> but postpones all side-effects of subscription and affects error propagation timing.
461 /// </para>
462 /// <para>
463 /// The side-effects of subscribing to the source sequence will be run on the default scheduler. Observer callbacks will not be affected.
464 /// </para>
465 /// </remarks>
466 public static IObservable<TSource> DelaySubscription<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime)
467 {
468 if (source == null)
469 throw new ArgumentNullException("source");
470
471 return s_impl.DelaySubscription<TSource>(source, dueTime);
472 }
473
474 /// <summary>
475 /// Time shifts the observable sequence by delaying the subscription to the specified absolute time, using the specified scheduler to run timers.
476 /// </summary>
477 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
478 /// <param name="source">Source sequence to delay subscription for.</param>
479 /// <param name="dueTime">Absolute time to perform the subscription at.</param>
480 /// <param name="scheduler">Scheduler to run the subscription delay timer on.</param>
481 /// <returns>Time-shifted sequence.</returns>
482 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
483 /// <remarks>
484 /// <para>
485 /// This operator is more efficient than <see cref="Observable.Delay{T}(IObservable{T}, DateTimeOffset, IScheduler)">Delay</see> but postpones all side-effects of subscription and affects error propagation timing.
486 /// </para>
487 /// <para>
488 /// The side-effects of subscribing to the source sequence will be run on the specified scheduler. Observer callbacks will not be affected.
489 /// </para>
490 /// </remarks>
491 public static IObservable<TSource> DelaySubscription<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime, IScheduler scheduler)
492 {
493 if (source == null)
494 throw new ArgumentNullException("source");
495 if (scheduler == null)
496 throw new ArgumentNullException("scheduler");
497
498 return s_impl.DelaySubscription<TSource>(source, dueTime, scheduler);
499 }
500
501 #endregion
502
503 #region + Generate +
504
505 /// <summary>
506 /// Generates an observable sequence by running a state-driven and temporal loop producing the sequence's elements.
507 /// </summary>
508 /// <typeparam name="TState">The type of the state used in the generator loop.</typeparam>
509 /// <typeparam name="TResult">The type of the elements in the produced sequence.</typeparam>
510 /// <param name="initialState">Initial state.</param>
511 /// <param name="condition">Condition to terminate generation (upon returning false).</param>
512 /// <param name="iterate">Iteration step function.</param>
513 /// <param name="resultSelector">Selector function for results produced in the sequence.</param>
514 /// <param name="timeSelector">Time selector function to control the speed of values being produced each iteration.</param>
515 /// <returns>The generated sequence.</returns>
516 /// <exception cref="ArgumentNullException"><paramref name="condition"/> or <paramref name="iterate"/> or <paramref name="resultSelector"/> or <paramref name="timeSelector"/> is null.</exception>
517 public static IObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, TimeSpan> timeSelector)
518 {
519 if (condition == null)
520 throw new ArgumentNullException("condition");
521 if (iterate == null)
522 throw new ArgumentNullException("iterate");
523 if (resultSelector == null)
524 throw new ArgumentNullException("resultSelector");
525 if (timeSelector == null)
526 throw new ArgumentNullException("timeSelector");
527
528 return s_impl.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector);
529 }
530
531 /// <summary>
532 /// Generates an observable sequence by running a state-driven and temporal loop producing the sequence's elements, using the specified scheduler to run timers and to send out observer messages.
533 /// </summary>
534 /// <typeparam name="TState">The type of the state used in the generator loop.</typeparam>
535 /// <typeparam name="TResult">The type of the elements in the produced sequence.</typeparam>
536 /// <param name="initialState">Initial state.</param>
537 /// <param name="condition">Condition to terminate generation (upon returning false).</param>
538 /// <param name="iterate">Iteration step function.</param>
539 /// <param name="resultSelector">Selector function for results produced in the sequence.</param>
540 /// <param name="timeSelector">Time selector function to control the speed of values being produced each iteration.</param>
541 /// <param name="scheduler">Scheduler on which to run the generator loop.</param>
542 /// <returns>The generated sequence.</returns>
543 /// <exception cref="ArgumentNullException"><paramref name="condition"/> or <paramref name="iterate"/> or <paramref name="resultSelector"/> or <paramref name="timeSelector"/> or <paramref name="scheduler"/> is null.</exception>
544 public static IObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, TimeSpan> timeSelector, IScheduler scheduler)
545 {
546 if (condition == null)
547 throw new ArgumentNullException("condition");
548 if (iterate == null)
549 throw new ArgumentNullException("iterate");
550 if (resultSelector == null)
551 throw new ArgumentNullException("resultSelector");
552 if (timeSelector == null)
553 throw new ArgumentNullException("timeSelector");
554 if (scheduler == null)
555 throw new ArgumentNullException("scheduler");
556
557 return s_impl.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector, scheduler);
558 }
559
560 /// <summary>
561 /// Generates an observable sequence by running a state-driven and temporal loop producing the sequence's elements.
562 /// </summary>
563 /// <typeparam name="TState">The type of the state used in the generator loop.</typeparam>
564 /// <typeparam name="TResult">The type of the elements in the produced sequence.</typeparam>
565 /// <param name="initialState">Initial state.</param>
566 /// <param name="condition">Condition to terminate generation (upon returning false).</param>
567 /// <param name="iterate">Iteration step function.</param>
568 /// <param name="resultSelector">Selector function for results produced in the sequence.</param>
569 /// <param name="timeSelector">Time selector function to control the speed of values being produced each iteration.</param>
570 /// <returns>The generated sequence.</returns>
571 /// <exception cref="ArgumentNullException"><paramref name="condition"/> or <paramref name="iterate"/> or <paramref name="resultSelector"/> or <paramref name="timeSelector"/> is null.</exception>
572 public static IObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, DateTimeOffset> timeSelector)
573 {
574 if (condition == null)
575 throw new ArgumentNullException("condition");
576 if (iterate == null)
577 throw new ArgumentNullException("iterate");
578 if (resultSelector == null)
579 throw new ArgumentNullException("resultSelector");
580 if (timeSelector == null)
581 throw new ArgumentNullException("timeSelector");
582
583 return s_impl.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector);
584 }
585
586 /// <summary>
587 /// Generates an observable sequence by running a state-driven and temporal loop producing the sequence's elements, using the specified scheduler to run timers and to send out observer messages.
588 /// </summary>
589 /// <typeparam name="TState">The type of the state used in the generator loop.</typeparam>
590 /// <typeparam name="TResult">The type of the elements in the produced sequence.</typeparam>
591 /// <param name="initialState">Initial state.</param>
592 /// <param name="condition">Condition to terminate generation (upon returning false).</param>
593 /// <param name="iterate">Iteration step function.</param>
594 /// <param name="resultSelector">Selector function for results produced in the sequence.</param>
595 /// <param name="timeSelector">Time selector function to control the speed of values being produced each iteration.</param>
596 /// <param name="scheduler">Scheduler on which to run the generator loop.</param>
597 /// <returns>The generated sequence.</returns>
598 /// <exception cref="ArgumentNullException"><paramref name="condition"/> or <paramref name="iterate"/> or <paramref name="resultSelector"/> or <paramref name="timeSelector"/> or <paramref name="scheduler"/> is null.</exception>
599 public static IObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, DateTimeOffset> timeSelector, IScheduler scheduler)
600 {
601 if (condition == null)
602 throw new ArgumentNullException("condition");
603 if (iterate == null)
604 throw new ArgumentNullException("iterate");
605 if (resultSelector == null)
606 throw new ArgumentNullException("resultSelector");
607 if (timeSelector == null)
608 throw new ArgumentNullException("timeSelector");
609 if (scheduler == null)
610 throw new ArgumentNullException("scheduler");
611
612 return s_impl.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector, scheduler);
613 }
614
615 #endregion
616
617 #region + Interval +
618
619 /// <summary>
620 /// Returns an observable sequence that produces a value after each period.
621 /// </summary>
622 /// <param name="period">Period for producing the values in the resulting sequence. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>
623 /// <returns>An observable sequence that produces a value after each period.</returns>
624 /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
625 /// <remarks>
626 /// Intervals are measured between the start of subsequent notifications, not between the end of the previous and the start of the next notification.
627 /// If the observer takes longer than the interval period to handle the message, the subsequent notification will be delivered immediately after the
628 /// current one has been handled. In case you need to control the time between the end and the start of consecutive notifications, consider using the
629 /// <see cref="Observable.Generate{TState, TResult}(TState, Func{TState, bool}, Func{TState, TState}, Func{TState, TResult}, Func{TState, TimeSpan})"/>
630 /// operator instead.
631 /// </remarks>
632 public static IObservable<long> Interval(TimeSpan period)
633 {
634 if (period < TimeSpan.Zero)
635 throw new ArgumentOutOfRangeException("period");
636
637 return s_impl.Interval(period);
638 }
639
640 /// <summary>
641 /// Returns an observable sequence that produces a value after each period, using the specified scheduler to run timers and to send out observer messages.
642 /// </summary>
643 /// <param name="period">Period for producing the values in the resulting sequence. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>
644 /// <param name="scheduler">Scheduler to run the timer on.</param>
645 /// <returns>An observable sequence that produces a value after each period.</returns>
646 /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
647 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
648 /// <remarks>
649 /// Intervals are measured between the start of subsequent notifications, not between the end of the previous and the start of the next notification.
650 /// If the observer takes longer than the interval period to handle the message, the subsequent notification will be delivered immediately after the
651 /// current one has been handled. In case you need to control the time between the end and the start of consecutive notifications, consider using the
652 /// <see cref="Observable.Generate{TState, TResult}(TState, Func{TState, bool}, Func{TState, TState}, Func{TState, TResult}, Func{TState, TimeSpan}, IScheduler)"/>
653 /// operator instead.
654 /// </remarks>
655 public static IObservable<long> Interval(TimeSpan period, IScheduler scheduler)
656 {
657 if (period < TimeSpan.Zero)
658 throw new ArgumentOutOfRangeException("period");
659 if (scheduler == null)
660 throw new ArgumentNullException("scheduler");
661
662 return s_impl.Interval(period, scheduler);
663 }
664
665 #endregion
666
667 #region + Sample +
668
669 /// <summary>
670 /// Samples the observable sequence at each interval.
671 /// Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.
672 /// </summary>
673 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
674 /// <param name="source">Source sequence to sample.</param>
675 /// <param name="interval">Interval at which to sample. If this value is equal to TimeSpan.Zero, the scheduler will continuously sample the stream.</param>
676 /// <returns>Sampled observable sequence.</returns>
677 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
678 /// <exception cref="ArgumentOutOfRangeException"><paramref name="interval"/> is less than TimeSpan.Zero.</exception>
679 /// <remarks>
680 /// Specifying a TimeSpan.Zero value for <paramref name="interval"/> doesn't guarantee all source sequence elements will be preserved. This is a side-effect
681 /// of the asynchrony introduced by the scheduler, where the sampling action may not execute immediately, despite the TimeSpan.Zero due time.
682 /// </remarks>
683 public static IObservable<TSource> Sample<TSource>(this IObservable<TSource> source, TimeSpan interval)
684 {
685 if (source == null)
686 throw new ArgumentNullException("source");
687 if (interval < TimeSpan.Zero)
688 throw new ArgumentOutOfRangeException("interval");
689
690 return s_impl.Sample<TSource>(source, interval);
691 }
692
693 /// <summary>
694 /// Samples the observable sequence at each interval, using the specified scheduler to run sampling timers.
695 /// Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.
696 /// </summary>
697 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
698 /// <param name="source">Source sequence to sample.</param>
699 /// <param name="interval">Interval at which to sample. If this value is equal to TimeSpan.Zero, the scheduler will continuously sample the stream.</param>
700 /// <param name="scheduler">Scheduler to run the sampling timer on.</param>
701 /// <returns>Sampled observable sequence.</returns>
702 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
703 /// <exception cref="ArgumentOutOfRangeException"><paramref name="interval"/> is less than TimeSpan.Zero.</exception>
704 /// <remarks>
705 /// Specifying a TimeSpan.Zero value for <paramref name="interval"/> doesn't guarantee all source sequence elements will be preserved. This is a side-effect
706 /// of the asynchrony introduced by the scheduler, where the sampling action may not execute immediately, despite the TimeSpan.Zero due time.
707 /// </remarks>
708 public static IObservable<TSource> Sample<TSource>(this IObservable<TSource> source, TimeSpan interval, IScheduler scheduler)
709 {
710 if (source == null)
711 throw new ArgumentNullException("source");
712 if (interval < TimeSpan.Zero)
713 throw new ArgumentOutOfRangeException("interval");
714 if (scheduler == null)
715 throw new ArgumentNullException("scheduler");
716
717 return s_impl.Sample<TSource>(source, interval, scheduler);
718 }
719
720 /// <summary>
721 /// Samples the source observable sequence using a samper observable sequence producing sampling ticks.
722 /// Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.
723 /// </summary>
724 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
725 /// <typeparam name="TSample">The type of the elements in the sampling sequence.</typeparam>
726 /// <param name="source">Source sequence to sample.</param>
727 /// <param name="sampler">Sampling tick sequence.</param>
728 /// <returns>Sampled observable sequence.</returns>
729 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="sampler"/> is null.</exception>
730 public static IObservable<TSource> Sample<TSource, TSample>(this IObservable<TSource> source, IObservable<TSample> sampler)
731 {
732 if (source == null)
733 throw new ArgumentNullException("source");
734 if (sampler == null)
735 throw new ArgumentNullException("sampler");
736
737 return s_impl.Sample<TSource, TSample>(source, sampler);
738 }
739
740 #endregion
741
742 #region + Skip +
743
744 /// <summary>
745 /// Skips elements for the specified duration from the start of the observable source sequence.
746 /// </summary>
747 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
748 /// <param name="source">Source sequence to skip elements for.</param>
749 /// <param name="duration">Duration for skipping elements from the start of the sequence.</param>
750 /// <returns>An observable sequence with the elements skipped during the specified duration from the start of the source sequence.</returns>
751 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
752 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
753 /// <remarks>
754 /// <para>
755 /// Specifying a TimeSpan.Zero value for <paramref name="duration"/> doesn't guarantee no elements will be dropped from the start of the source sequence.
756 /// This is a side-effect of the asynchrony introduced by the scheduler, where the action that causes callbacks from the source sequence to be forwarded
757 /// may not execute immediately, despite the TimeSpan.Zero due time.
758 /// </para>
759 /// <para>
760 /// Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the <paramref name="duration"/>.
761 /// </para>
762 /// </remarks>
763 public static IObservable<TSource> Skip<TSource>(this IObservable<TSource> source, TimeSpan duration)
764 {
765 if (source == null)
766 throw new ArgumentNullException("source");
767 if (duration < TimeSpan.Zero)
768 throw new ArgumentOutOfRangeException("duration");
769
770 return s_impl.Skip<TSource>(source, duration);
771 }
772
773 /// <summary>
774 /// Skips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
775 /// </summary>
776 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
777 /// <param name="source">Source sequence to skip elements for.</param>
778 /// <param name="duration">Duration for skipping elements from the start of the sequence.</param>
779 /// <param name="scheduler">Scheduler to run the timer on.</param>
780 /// <returns>An observable sequence with the elements skipped during the specified duration from the start of the source sequence.</returns>
781 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
782 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
783 /// <remarks>
784 /// <para>
785 /// Specifying a TimeSpan.Zero value for <paramref name="duration"/> doesn't guarantee no elements will be dropped from the start of the source sequence.
786 /// This is a side-effect of the asynchrony introduced by the scheduler, where the action that causes callbacks from the source sequence to be forwarded
787 /// may not execute immediately, despite the TimeSpan.Zero due time.
788 /// </para>
789 /// <para>
790 /// Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the <paramref name="duration"/>.
791 /// </para>
792 /// </remarks>
793 public static IObservable<TSource> Skip<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
794 {
795 if (source == null)
796 throw new ArgumentNullException("source");
797 if (duration < TimeSpan.Zero)
798 throw new ArgumentOutOfRangeException("duration");
799 if (scheduler == null)
800 throw new ArgumentNullException("scheduler");
801
802 return s_impl.Skip<TSource>(source, duration, scheduler);
803 }
804
805 #endregion
806
807 #region + SkipLast +
808
809 /// <summary>
810 /// Skips elements for the specified duration from the end of the observable source sequence.
811 /// </summary>
812 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
813 /// <param name="source">Source sequence to skip elements for.</param>
814 /// <param name="duration">Duration for skipping elements from the end of the sequence.</param>
815 /// <returns>An observable sequence with the elements skipped during the specified duration from the end of the source sequence.</returns>
816 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
817 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
818 /// <remarks>
819 /// This operator accumulates a queue with a length enough to store elements received during the initial <paramref name="duration"/> window.
820 /// As more elements are received, elements older than the specified <paramref name="duration"/> are taken from the queue and produced on the
821 /// result sequence. This causes elements to be delayed with <paramref name="duration"/>.
822 /// </remarks>
823 public static IObservable<TSource> SkipLast<TSource>(this IObservable<TSource> source, TimeSpan duration)
824 {
825 if (source == null)
826 throw new ArgumentNullException("source");
827 if (duration < TimeSpan.Zero)
828 throw new ArgumentOutOfRangeException("duration");
829
830 return s_impl.SkipLast<TSource>(source, duration);
831 }
832
833 /// <summary>
834 /// Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
835 /// </summary>
836 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
837 /// <param name="source">Source sequence to skip elements for.</param>
838 /// <param name="duration">Duration for skipping elements from the end of the sequence.</param>
839 /// <param name="scheduler">Scheduler to run the timer on.</param>
840 /// <returns>An observable sequence with the elements skipped during the specified duration from the end of the source sequence.</returns>
841 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
842 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
843 /// <remarks>
844 /// This operator accumulates a queue with a length enough to store elements received during the initial <paramref name="duration"/> window.
845 /// As more elements are received, elements older than the specified <paramref name="duration"/> are taken from the queue and produced on the
846 /// result sequence. This causes elements to be delayed with <paramref name="duration"/>.
847 /// </remarks>
848 public static IObservable<TSource> SkipLast<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
849 {
850 if (source == null)
851 throw new ArgumentNullException("source");
852 if (duration < TimeSpan.Zero)
853 throw new ArgumentOutOfRangeException("duration");
854 if (scheduler == null)
855 throw new ArgumentNullException("scheduler");
856
857 return s_impl.SkipLast<TSource>(source, duration, scheduler);
858 }
859
860 #endregion
861
862 #region + SkipUntil +
863
864 /// <summary>
865 /// Skips elements from the observable source sequence until the specified start time.
866 /// </summary>
867 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
868 /// <param name="source">Source sequence to skip elements for.</param>
869 /// <param name="startTime">Time to start taking elements from the source sequence. If this value is less than or equal to DateTimeOffset.UtcNow, no elements will be skipped.</param>
870 /// <returns>An observable sequence with the elements skipped until the specified start time.</returns>
871 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
872 /// <remarks>
873 /// Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the <paramref name="startTime"/>.
874 /// </remarks>
875 public static IObservable<TSource> SkipUntil<TSource>(this IObservable<TSource> source, DateTimeOffset startTime)
876 {
877 if (source == null)
878 throw new ArgumentNullException("source");
879
880 return s_impl.SkipUntil<TSource>(source, startTime);
881 }
882
883 /// <summary>
884 /// Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
885 /// </summary>
886 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
887 /// <param name="source">Source sequence to skip elements for.</param>
888 /// <param name="startTime">Time to start taking elements from the source sequence. If this value is less than or equal to DateTimeOffset.UtcNow, no elements will be skipped.</param>
889 /// <param name="scheduler">Scheduler to run the timer on.</param>
890 /// <returns>An observable sequence with the elements skipped until the specified start time.</returns>
891 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
892 /// <remarks>
893 /// Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the <paramref name="startTime"/>.
894 /// </remarks>
895 public static IObservable<TSource> SkipUntil<TSource>(this IObservable<TSource> source, DateTimeOffset startTime, IScheduler scheduler)
896 {
897 if (source == null)
898 throw new ArgumentNullException("source");
899 if (scheduler == null)
900 throw new ArgumentNullException("scheduler");
901
902 return s_impl.SkipUntil<TSource>(source, startTime, scheduler);
903 }
904
905 #endregion
906
907 #region + Take +
908
909 /// <summary>
910 /// Takes elements for the specified duration from the start of the observable source sequence.
911 /// </summary>
912 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
913 /// <param name="source">Source sequence to take elements from.</param>
914 /// <param name="duration">Duration for taking elements from the start of the sequence.</param>
915 /// <returns>An observable sequence with the elements taken during the specified duration from the start of the source sequence.</returns>
916 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
917 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
918 /// <remarks>
919 /// Specifying a TimeSpan.Zero value for <paramref name="duration"/> doesn't guarantee an empty sequence will be returned. This is a side-effect
920 /// of the asynchrony introduced by the scheduler, where the action that stops forwarding callbacks from the source sequence may not execute
921 /// immediately, despite the TimeSpan.Zero due time.
922 /// </remarks>
923 public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, TimeSpan duration)
924 {
925 if (source == null)
926 throw new ArgumentNullException("source");
927 if (duration < TimeSpan.Zero)
928 throw new ArgumentOutOfRangeException("duration");
929
930 return s_impl.Take<TSource>(source, duration);
931 }
932
933 /// <summary>
934 /// Takes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
935 /// </summary>
936 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
937 /// <param name="source">Source sequence to take elements from.</param>
938 /// <param name="duration">Duration for taking elements from the start of the sequence.</param>
939 /// <param name="scheduler">Scheduler to run the timer on.</param>
940 /// <returns>An observable sequence with the elements taken during the specified duration from the start of the source sequence.</returns>
941 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
942 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
943 /// <remarks>
944 /// Specifying a TimeSpan.Zero value for <paramref name="duration"/> doesn't guarantee an empty sequence will be returned. This is a side-effect
945 /// of the asynchrony introduced by the scheduler, where the action that stops forwarding callbacks from the source sequence may not execute
946 /// immediately, despite the TimeSpan.Zero due time.
947 /// </remarks>
948 public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
949 {
950 if (source == null)
951 throw new ArgumentNullException("source");
952 if (duration < TimeSpan.Zero)
953 throw new ArgumentOutOfRangeException("duration");
954 if (scheduler == null)
955 throw new ArgumentNullException("scheduler");
956
957 return s_impl.Take<TSource>(source, duration, scheduler);
958 }
959
960 #endregion
961
962 #region + TakeLast +
963
964 /// <summary>
965 /// Returns elements within the specified duration from the end of the observable source sequence.
966 /// </summary>
967 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
968 /// <param name="source">Source sequence to take elements from.</param>
969 /// <param name="duration">Duration for taking elements from the end of the sequence.</param>
970 /// <returns>An observable sequence with the elements taken during the specified duration from the end of the source sequence.</returns>
971 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
972 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
973 /// <remarks>
974 /// This operator accumulates a buffer with a length enough to store elements for any <paramref name="duration"/> window during the lifetime of
975 /// the source sequence. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the result elements
976 /// to be delayed with <paramref name="duration"/>.
977 /// </remarks>
978 public static IObservable<TSource> TakeLast<TSource>(this IObservable<TSource> source, TimeSpan duration)
979 {
980 if (source == null)
981 throw new ArgumentNullException("source");
982 if (duration < TimeSpan.Zero)
983 throw new ArgumentOutOfRangeException("duration");
984
985 return s_impl.TakeLast<TSource>(source, duration);
986 }
987
988 /// <summary>
989 /// Returns elements within the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
990 /// </summary>
991 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
992 /// <param name="source">Source sequence to take elements from.</param>
993 /// <param name="duration">Duration for taking elements from the end of the sequence.</param>
994 /// <param name="scheduler">Scheduler to run the timer on.</param>
995 /// <returns>An observable sequence with the elements taken during the specified duration from the end of the source sequence.</returns>
996 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
997 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
998 /// <remarks>
999 /// This operator accumulates a buffer with a length enough to store elements for any <paramref name="duration"/> window during the lifetime of
1000 /// the source sequence. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the result elements
1001 /// to be delayed with <paramref name="duration"/>.
1002 /// </remarks>
1003 public static IObservable<TSource> TakeLast<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
1004 {
1005 if (source == null)
1006 throw new ArgumentNullException("source");
1007 if (duration < TimeSpan.Zero)
1008 throw new ArgumentOutOfRangeException("duration");
1009 if (scheduler == null)
1010 throw new ArgumentNullException("scheduler");
1011
1012 return s_impl.TakeLast<TSource>(source, duration, scheduler);
1013 }
1014
1015 /// <summary>
1016 /// Returns elements within the specified duration from the end of the observable source sequence, using the specified schedulers to run timers and to drain the collected elements.
1017 /// </summary>
1018 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1019 /// <param name="source">Source sequence to take elements from.</param>
1020 /// <param name="duration">Duration for taking elements from the end of the sequence.</param>
1021 /// <param name="timerScheduler">Scheduler to run the timer on.</param>
1022 /// <param name="loopScheduler">Scheduler to drain the collected elements.</param>
1023 /// <returns>An observable sequence with the elements taken during the specified duration from the end of the source sequence.</returns>
1024 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="timerScheduler"/> or <paramref name="loopScheduler"/> is null.</exception>
1025 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
1026 /// <remarks>
1027 /// This operator accumulates a buffer with a length enough to store elements for any <paramref name="duration"/> window during the lifetime of
1028 /// the source sequence. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the result elements
1029 /// to be delayed with <paramref name="duration"/>.
1030 /// </remarks>
1031 public static IObservable<TSource> TakeLast<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler timerScheduler, IScheduler loopScheduler)
1032 {
1033 if (source == null)
1034 throw new ArgumentNullException("source");
1035 if (duration < TimeSpan.Zero)
1036 throw new ArgumentOutOfRangeException("duration");
1037 if (timerScheduler == null)
1038 throw new ArgumentNullException("timerScheduler");
1039 if (loopScheduler == null)
1040 throw new ArgumentNullException("loopScheduler");
1041
1042 return s_impl.TakeLast<TSource>(source, duration, timerScheduler, loopScheduler);
1043 }
1044
1045 #endregion
1046
1047 #region + TakeLastBuffer +
1048
1049 /// <summary>
1050 /// Returns a list with the elements within the specified duration from the end of the observable source sequence.
1051 /// </summary>
1052 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1053 /// <param name="source">Source sequence to take elements from.</param>
1054 /// <param name="duration">Duration for taking elements from the end of the sequence.</param>
1055 /// <returns>An observable sequence containing a single list with the elements taken during the specified duration from the end of the source sequence.</returns>
1056 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1057 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
1058 /// <remarks>
1059 /// This operator accumulates a buffer with a length enough to store elements for any <paramref name="duration"/> window during the lifetime of
1060 /// the source sequence. Upon completion of the source sequence, this buffer is produced on the result sequence.
1061 /// </remarks>
1062 public static IObservable<IList<TSource>> TakeLastBuffer<TSource>(this IObservable<TSource> source, TimeSpan duration)
1063 {
1064 if (source == null)
1065 throw new ArgumentNullException("source");
1066 if (duration < TimeSpan.Zero)
1067 throw new ArgumentOutOfRangeException("duration");
1068
1069 return s_impl.TakeLastBuffer<TSource>(source, duration);
1070 }
1071
1072 /// <summary>
1073 /// Returns a list with the elements within the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
1074 /// </summary>
1075 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1076 /// <param name="source">Source sequence to take elements from.</param>
1077 /// <param name="duration">Duration for taking elements from the end of the sequence.</param>
1078 /// <param name="scheduler">Scheduler to run the timer on.</param>
1079 /// <returns>An observable sequence containing a single list with the elements taken during the specified duration from the end of the source sequence.</returns>
1080 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1081 /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is less than TimeSpan.Zero.</exception>
1082 /// <remarks>
1083 /// This operator accumulates a buffer with a length enough to store elements for any <paramref name="duration"/> window during the lifetime of
1084 /// the source sequence. Upon completion of the source sequence, this buffer is produced on the result sequence.
1085 /// </remarks>
1086 public static IObservable<IList<TSource>> TakeLastBuffer<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
1087 {
1088 if (source == null)
1089 throw new ArgumentNullException("source");
1090 if (duration < TimeSpan.Zero)
1091 throw new ArgumentOutOfRangeException("duration");
1092 if (scheduler == null)
1093 throw new ArgumentNullException("scheduler");
1094
1095 return s_impl.TakeLastBuffer<TSource>(source, duration, scheduler);
1096 }
1097
1098 #endregion
1099
1100 #region + TakeUntil +
1101
1102 /// <summary>
1103 /// Takes elements for the specified duration until the specified end time.
1104 /// </summary>
1105 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1106 /// <param name="source">Source sequence to take elements from.</param>
1107 /// <param name="endTime">Time to stop taking elements from the source sequence. If this value is less than or equal to DateTimeOffset.UtcNow, the result stream will complete immediately.</param>
1108 /// <returns>An observable sequence with the elements taken until the specified end time.</returns>
1109 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1110 public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, DateTimeOffset endTime)
1111 {
1112 if (source == null)
1113 throw new ArgumentNullException("source");
1114
1115 return s_impl.TakeUntil<TSource>(source, endTime);
1116 }
1117
1118 /// <summary>
1119 /// Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.
1120 /// </summary>
1121 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1122 /// <param name="source">Source sequence to take elements from.</param>
1123 /// <param name="endTime">Time to stop taking elements from the source sequence. If this value is less than or equal to DateTimeOffset.UtcNow, the result stream will complete immediately.</param>
1124 /// <param name="scheduler">Scheduler to run the timer on.</param>
1125 /// <returns>An observable sequence with the elements taken until the specified end time.</returns>
1126 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1127 public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, DateTimeOffset endTime, IScheduler scheduler)
1128 {
1129 if (source == null)
1130 throw new ArgumentNullException("source");
1131 if (scheduler == null)
1132 throw new ArgumentNullException("scheduler");
1133
1134 return s_impl.TakeUntil<TSource>(source, endTime, scheduler);
1135 }
1136
1137 #endregion
1138
1139 #region + Throttle +
1140
1141 /// <summary>
1142 /// Ignores elements from an observable sequence which are followed by another element within a specified relative time duration.
1143 /// </summary>
1144 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1145 /// <param name="source">Source sequence to throttle.</param>
1146 /// <param name="dueTime">Throttling duration for each element.</param>
1147 /// <returns>The throttled sequence.</returns>
1148 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1149 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
1150 /// <remarks>
1151 /// <para>
1152 /// This operator throttles the source sequence by holding on to each element for the duration specified in <paramref name="dueTime"/>. If another
1153 /// element is produced within this time window, the element is dropped and a new timer is started for the current element, repeating this whole
1154 /// process. For streams that never have gaps larger than or equal to <paramref name="dueTime"/> between elements, the resulting stream won't
1155 /// produce any elements. In order to reduce the volume of a stream whilst guaranteeing the periodic production of elements, consider using the
1156 /// Observable.Sample set of operators.
1157 /// </para>
1158 /// <para>
1159 /// Specifying a TimeSpan.Zero value for <paramref name="dueTime"/> is not recommended but supported, causing throttling timers to be scheduled
1160 /// that are due immediately. However, this doesn't guarantee all elements will be retained in the result sequence. This is a side-effect of the
1161 /// asynchrony introduced by the scheduler, where the action to forward the current element may not execute immediately, despite the TimeSpan.Zero
1162 /// due time. In such cases, the next element may arrive before the scheduler gets a chance to run the throttling action.
1163 /// </para>
1164 /// </remarks>
1165 public static IObservable<TSource> Throttle<TSource>(this IObservable<TSource> source, TimeSpan dueTime)
1166 {
1167 if (source == null)
1168 throw new ArgumentNullException("source");
1169 if (dueTime < TimeSpan.Zero)
1170 throw new ArgumentOutOfRangeException("dueTime");
1171
1172 return s_impl.Throttle<TSource>(source, dueTime);
1173 }
1174
1175 /// <summary>
1176 /// Ignores elements from an observable sequence which are followed by another element within a specified relative time duration, using the specified scheduler to run throttling timers.
1177 /// </summary>
1178 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1179 /// <param name="source">Source sequence to throttle.</param>
1180 /// <param name="dueTime">Throttling duration for each element.</param>
1181 /// <param name="scheduler">Scheduler to run the throttle timers on.</param>
1182 /// <returns>The throttled sequence.</returns>
1183 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1184 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
1185 /// <remarks>
1186 /// <para>
1187 /// This operator throttles the source sequence by holding on to each element for the duration specified in <paramref name="dueTime"/>. If another
1188 /// element is produced within this time window, the element is dropped and a new timer is started for the current element, repeating this whole
1189 /// process. For streams that never have gaps larger than or equal to <paramref name="dueTime"/> between elements, the resulting stream won't
1190 /// produce any elements. In order to reduce the volume of a stream whilst guaranteeing the periodic production of elements, consider using the
1191 /// Observable.Sample set of operators.
1192 /// </para>
1193 /// <para>
1194 /// Specifying a TimeSpan.Zero value for <paramref name="dueTime"/> is not recommended but supported, causing throttling timers to be scheduled
1195 /// that are due immediately. However, this doesn't guarantee all elements will be retained in the result sequence. This is a side-effect of the
1196 /// asynchrony introduced by the scheduler, where the action to forward the current element may not execute immediately, despite the TimeSpan.Zero
1197 /// due time. In such cases, the next element may arrive before the scheduler gets a chance to run the throttling action.
1198 /// </para>
1199 /// </remarks>
1200 public static IObservable<TSource> Throttle<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
1201 {
1202 if (source == null)
1203 throw new ArgumentNullException("source");
1204 if (dueTime < TimeSpan.Zero)
1205 throw new ArgumentOutOfRangeException("dueTime");
1206 if (scheduler == null)
1207 throw new ArgumentNullException("scheduler");
1208
1209 return s_impl.Throttle<TSource>(source, dueTime, scheduler);
1210 }
1211
1212 /// <summary>
1213 /// Ignores elements from an observable sequence which are followed by another value within a computed throttle duration.
1214 /// </summary>
1215 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1216 /// <typeparam name="TThrottle">The type of the elements in the throttle sequences selected for each element in the source sequence.</typeparam>
1217 /// <param name="source">Source sequence to throttle.</param>
1218 /// <param name="throttleDurationSelector">Selector function to retrieve a sequence indicating the throttle duration for each given element.</param>
1219 /// <returns>The throttled sequence.</returns>
1220 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="throttleDurationSelector"/> is null.</exception>
1221 /// <remarks>
1222 /// This operator throttles the source sequence by holding on to each element for the duration denoted by <paramref name="throttleDurationSelector"/>.
1223 /// If another element is produced within this time window, the element is dropped and a new timer is started for the current element, repeating this
1224 /// whole process. For streams where the duration computed by applying the <paramref name="throttleDurationSelector"/> to each element overlaps with
1225 /// the occurrence of the successor element, the resulting stream won't produce any elements. In order to reduce the volume of a stream whilst
1226 /// guaranteeing the periodic production of elements, consider using the Observable.Sample set of operators.
1227 /// </remarks>
1228 public static IObservable<TSource> Throttle<TSource, TThrottle>(this IObservable<TSource> source, Func<TSource, IObservable<TThrottle>> throttleDurationSelector)
1229 {
1230 if (source == null)
1231 throw new ArgumentNullException("source");
1232 if (throttleDurationSelector == null)
1233 throw new ArgumentNullException("throttleDurationSelector");
1234
1235 return s_impl.Throttle<TSource, TThrottle>(source, throttleDurationSelector);
1236 }
1237
1238 #endregion
1239
1240 #region + TimeInterval +
1241
1242 /// <summary>
1243 /// Records the time interval between consecutive elements in an observable sequence.
1244 /// </summary>
1245 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1246 /// <param name="source">Source sequence to record time intervals for.</param>
1247 /// <returns>An observable sequence with time interval information on elements.</returns>
1248 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1249 public static IObservable<System.Reactive.TimeInterval<TSource>> TimeInterval<TSource>(this IObservable<TSource> source)
1250 {
1251 if (source == null)
1252 throw new ArgumentNullException("source");
1253
1254 return s_impl.TimeInterval<TSource>(source);
1255 }
1256
1257 /// <summary>
1258 /// Records the time interval between consecutive elements in an observable sequence, using the specified scheduler to compute time intervals.
1259 /// </summary>
1260 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1261 /// <param name="source">Source sequence to record time intervals for.</param>
1262 /// <param name="scheduler">Scheduler used to compute time intervals.</param>
1263 /// <returns>An observable sequence with time interval information on elements.</returns>
1264 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1265 public static IObservable<System.Reactive.TimeInterval<TSource>> TimeInterval<TSource>(this IObservable<TSource> source, IScheduler scheduler)
1266 {
1267 if (source == null)
1268 throw new ArgumentNullException("source");
1269 if (scheduler == null)
1270 throw new ArgumentNullException("scheduler");
1271
1272 return s_impl.TimeInterval<TSource>(source, scheduler);
1273 }
1274
1275 #endregion
1276
1277 #region + Timeout +
1278
1279 #region TimeSpan
1280
1281 /// <summary>
1282 /// Applies a timeout policy for each element in the observable sequence.
1283 /// If the next element isn't received within the specified timeout duration starting from its predecessor, a TimeoutException is propagated to the observer.
1284 /// </summary>
1285 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1286 /// <param name="source">Source sequence to perform a timeout for.</param>
1287 /// <param name="dueTime">Maximum duration between values before a timeout occurs.</param>
1288 /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>
1289 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1290 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
1291 /// <exception cref="TimeoutException">(Asynchronous) If no element is produced within <paramref name="dueTime"/> from the previous element.</exception>
1292 /// <remarks>
1293 /// <para>
1294 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1295 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1296 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1297 /// </para>
1298 /// <para>
1299 /// Specifying a TimeSpan.Zero value for <paramref name="dueTime"/> is not recommended but supported, causing timeout timers to be scheduled that are due
1300 /// immediately. However, this doesn't guarantee a timeout will occur, even for the first element. This is a side-effect of the asynchrony introduced by the
1301 /// scheduler, where the action to propagate a timeout may not execute immediately, despite the TimeSpan.Zero due time. In such cases, the next element may
1302 /// arrive before the scheduler gets a chance to run the timeout action.
1303 /// </para>
1304 /// </remarks>
1305 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, TimeSpan dueTime)
1306 {
1307 if (source == null)
1308 throw new ArgumentNullException("source");
1309 if (dueTime < TimeSpan.Zero)
1310 throw new ArgumentOutOfRangeException("dueTime");
1311
1312 return s_impl.Timeout<TSource>(source, dueTime);
1313 }
1314
1315 /// <summary>
1316 /// Applies a timeout policy for each element in the observable sequence, using the specified scheduler to run timeout timers.
1317 /// If the next element isn't received within the specified timeout duration starting from its predecessor, a TimeoutException is propagated to the observer.
1318 /// </summary>
1319 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1320 /// <param name="source">Source sequence to perform a timeout for.</param>
1321 /// <param name="dueTime">Maximum duration between values before a timeout occurs.</param>
1322 /// <param name="scheduler">Scheduler to run the timeout timers on.</param>
1323 /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>
1324 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1325 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
1326 /// <exception cref="TimeoutException">(Asynchronous) If no element is produced within <paramref name="dueTime"/> from the previous element.</exception>
1327 /// <remarks>
1328 /// <para>
1329 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1330 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1331 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1332 /// </para>
1333 /// <para>
1334 /// Specifying a TimeSpan.Zero value for <paramref name="dueTime"/> is not recommended but supported, causing timeout timers to be scheduled that are due
1335 /// immediately. However, this doesn't guarantee a timeout will occur, even for the first element. This is a side-effect of the asynchrony introduced by the
1336 /// scheduler, where the action to propagate a timeout may not execute immediately, despite the TimeSpan.Zero due time. In such cases, the next element may
1337 /// arrive before the scheduler gets a chance to run the timeout action.
1338 /// </para>
1339 /// </remarks>
1340 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
1341 {
1342 if (source == null)
1343 throw new ArgumentNullException("source");
1344 if (dueTime < TimeSpan.Zero)
1345 throw new ArgumentOutOfRangeException("dueTime");
1346 if (scheduler == null)
1347 throw new ArgumentNullException("scheduler");
1348
1349 return s_impl.Timeout<TSource>(source, dueTime, scheduler);
1350 }
1351
1352 /// <summary>
1353 /// Applies a timeout policy for each element in the observable sequence.
1354 /// If the next element isn't received within the specified timeout duration starting from its predecessor, the other observable sequence is used to produce future messages from that point on.
1355 /// </summary>
1356 /// <typeparam name="TSource">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>
1357 /// <param name="source">Source sequence to perform a timeout for.</param>
1358 /// <param name="dueTime">Maximum duration between values before a timeout occurs.</param>
1359 /// <param name="other">Sequence to return in case of a timeout.</param>
1360 /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>
1361 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="other"/> is null.</exception>
1362 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
1363 /// <remarks>
1364 /// <para>
1365 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1366 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1367 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1368 /// </para>
1369 /// <para>
1370 /// Specifying a TimeSpan.Zero value for <paramref name="dueTime"/> is not recommended but supported, causing timeout timers to be scheduled that are due
1371 /// immediately. However, this doesn't guarantee a timeout will occur, even for the first element. This is a side-effect of the asynchrony introduced by the
1372 /// scheduler, where the action to propagate a timeout may not execute immediately, despite the TimeSpan.Zero due time. In such cases, the next element may
1373 /// arrive before the scheduler gets a chance to run the timeout action.
1374 /// </para>
1375 /// </remarks>
1376 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IObservable<TSource> other)
1377 {
1378 if (source == null)
1379 throw new ArgumentNullException("source");
1380 if (dueTime < TimeSpan.Zero)
1381 throw new ArgumentOutOfRangeException("dueTime");
1382 if (other == null)
1383 throw new ArgumentNullException("other");
1384
1385 return s_impl.Timeout<TSource>(source, dueTime, other);
1386 }
1387
1388 /// <summary>
1389 /// Applies a timeout policy for each element in the observable sequence, using the specified scheduler to run timeout timers.
1390 /// If the next element isn't received within the specified timeout duration starting from its predecessor, the other observable sequence is used to produce future messages from that point on.
1391 /// </summary>
1392 /// <typeparam name="TSource">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>
1393 /// <param name="source">Source sequence to perform a timeout for.</param>
1394 /// <param name="dueTime">Maximum duration between values before a timeout occurs.</param>
1395 /// <param name="other">Sequence to return in case of a timeout.</param>
1396 /// <param name="scheduler">Scheduler to run the timeout timers on.</param>
1397 /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>
1398 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="other"/> or <paramref name="scheduler"/> is null.</exception>
1399 /// <exception cref="ArgumentOutOfRangeException"><paramref name="dueTime"/> is less than TimeSpan.Zero.</exception>
1400 /// <remarks>
1401 /// <para>
1402 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1403 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1404 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1405 /// </para>
1406 /// <para>
1407 /// Specifying a TimeSpan.Zero value for <paramref name="dueTime"/> is not recommended but supported, causing timeout timers to be scheduled that are due
1408 /// immediately. However, this doesn't guarantee a timeout will occur, even for the first element. This is a side-effect of the asynchrony introduced by the
1409 /// scheduler, where the action to propagate a timeout may not execute immediately, despite the TimeSpan.Zero due time. In such cases, the next element may
1410 /// arrive before the scheduler gets a chance to run the timeout action.
1411 /// </para>
1412 /// </remarks>
1413 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IObservable<TSource> other, IScheduler scheduler)
1414 {
1415 if (source == null)
1416 throw new ArgumentNullException("source");
1417 if (dueTime < TimeSpan.Zero)
1418 throw new ArgumentOutOfRangeException("dueTime");
1419 if (other == null)
1420 throw new ArgumentNullException("other");
1421 if (scheduler == null)
1422 throw new ArgumentNullException("scheduler");
1423
1424 return s_impl.Timeout<TSource>(source, dueTime, other, scheduler);
1425 }
1426
1427 #endregion
1428
1429 #region DateTimeOffset
1430
1431 /// <summary>
1432 /// Applies a timeout policy to the observable sequence based on an absolute time.
1433 /// If the sequence doesn't terminate before the specified absolute due time, a TimeoutException is propagated to the observer.
1434 /// </summary>
1435 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1436 /// <param name="source">Source sequence to perform a timeout for.</param>
1437 /// <param name="dueTime">Time when a timeout occurs. If this value is less than or equal to DateTimeOffset.UtcNow, the timeout occurs immediately.</param>
1438 /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>
1439 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1440 /// <exception cref="TimeoutException">(Asynchronous) If the sequence hasn't terminated before <paramref name="dueTime"/>.</exception>
1441 /// <remarks>
1442 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1443 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1444 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1445 /// </remarks>
1446 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime)
1447 {
1448 if (source == null)
1449 throw new ArgumentNullException("source");
1450
1451 return s_impl.Timeout<TSource>(source, dueTime);
1452 }
1453
1454 /// <summary>
1455 /// Applies a timeout policy to the observable sequence based on an absolute time, using the specified scheduler to run timeout timers.
1456 /// If the sequence doesn't terminate before the specified absolute due time, a TimeoutException is propagated to the observer.
1457 /// </summary>
1458 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1459 /// <param name="source">Source sequence to perform a timeout for.</param>
1460 /// <param name="dueTime">Time when a timeout occurs. If this value is less than or equal to DateTimeOffset.UtcNow, the timeout occurs immediately.</param>
1461 /// <param name="scheduler">Scheduler to run the timeout timers on.</param>
1462 /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>
1463 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1464 /// <exception cref="TimeoutException">(Asynchronous) If the sequence hasn't terminated before <paramref name="dueTime"/>.</exception>
1465 /// <remarks>
1466 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1467 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1468 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1469 /// </remarks>
1470 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime, IScheduler scheduler)
1471 {
1472 if (source == null)
1473 throw new ArgumentNullException("source");
1474 if (scheduler == null)
1475 throw new ArgumentNullException("scheduler");
1476
1477 return s_impl.Timeout<TSource>(source, dueTime, scheduler);
1478 }
1479
1480 /// <summary>
1481 /// Applies a timeout policy to the observable sequence based on an absolute time.
1482 /// If the sequence doesn't terminate before the specified absolute due time, the other observable sequence is used to produce future messages from that point on.
1483 /// </summary>
1484 /// <typeparam name="TSource">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>
1485 /// <param name="source">Source sequence to perform a timeout for.</param>
1486 /// <param name="dueTime">Time when a timeout occurs. If this value is less than or equal to DateTimeOffset.UtcNow, the timeout occurs immediately.</param>
1487 /// <param name="other">Sequence to return in case of a timeout.</param>
1488 /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>
1489 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="other"/> is null.</exception>
1490 /// <remarks>
1491 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1492 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1493 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1494 /// </remarks>
1495 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime, IObservable<TSource> other)
1496 {
1497 if (source == null)
1498 throw new ArgumentNullException("source");
1499 if (other == null)
1500 throw new ArgumentNullException("other");
1501
1502 return s_impl.Timeout<TSource>(source, dueTime, other);
1503 }
1504
1505 /// <summary>
1506 /// Applies a timeout policy to the observable sequence based on an absolute time, using the specified scheduler to run timeout timers.
1507 /// If the sequence doesn't terminate before the specified absolute due time, the other observable sequence is used to produce future messages from that point on.
1508 /// </summary>
1509 /// <typeparam name="TSource">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>
1510 /// <param name="source">Source sequence to perform a timeout for.</param>
1511 /// <param name="dueTime">Time when a timeout occurs. If this value is less than or equal to DateTimeOffset.UtcNow, the timeout occurs immediately.</param>
1512 /// <param name="other">Sequence to return in case of a timeout.</param>
1513 /// <param name="scheduler">Scheduler to run the timeout timers on.</param>
1514 /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>
1515 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="other"/> or <paramref name="scheduler"/> is null.</exception>
1516 /// <remarks>
1517 /// In case you only want to timeout on the first element, consider using the <see cref="Observable.Amb{TSource}(IObservable{TSource}, IObservable{TSource})"/>
1518 /// operator applied to the source sequence and a delayed <see cref="Observable.Throw{TResult}(Exception)"/> sequence. Alternatively, the general-purpose overload
1519 /// of Timeout, <see cref="Timeout{TSource, TTimeout}(IObservable{TSource}, IObservable{TTimeout}, Func{TSource, IObservable{TTimeout}})"/> can be used.
1520 /// </remarks>
1521 public static IObservable<TSource> Timeout<TSource>(this IObservable<TSource> source, DateTimeOffset dueTime, IObservable<TSource> other, IScheduler scheduler)
1522 {
1523 if (source == null)
1524 throw new ArgumentNullException("source");
1525 if (scheduler == null)
1526 throw new ArgumentNullException("scheduler");
1527 if (other == null)
1528 throw new ArgumentNullException("other");
1529
1530 return s_impl.Timeout<TSource>(source, dueTime, other, scheduler);
1531 }
1532
1533 #endregion
1534
1535 #region Duration selector
1536
1537 /// <summary>
1538 /// Applies a timeout policy to the observable sequence based on a timeout duration computed for each element.
1539 /// If the next element isn't received within the computed duration starting from its predecessor, a TimeoutException is propagated to the observer.
1540 /// </summary>
1541 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1542 /// <typeparam name="TTimeout">The type of the elements in the timeout sequences used to indicate the timeout duration for each element in the source sequence.</typeparam>
1543 /// <param name="source">Source sequence to perform a timeout for.</param>
1544 /// <param name="timeoutDurationSelector">Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.</param>
1545 /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>
1546 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="timeoutDurationSelector"/> is null.</exception>
1547 public static IObservable<TSource> Timeout<TSource, TTimeout>(this IObservable<TSource> source, Func<TSource, IObservable<TTimeout>> timeoutDurationSelector)
1548 {
1549 if (source == null)
1550 throw new ArgumentNullException("source");
1551 if (timeoutDurationSelector == null)
1552 throw new ArgumentNullException("timeoutDurationSelector");
1553
1554 return s_impl.Timeout<TSource, TTimeout>(source, timeoutDurationSelector);
1555 }
1556
1557 /// <summary>
1558 /// Applies a timeout policy to the observable sequence based on a timeout duration computed for each element.
1559 /// If the next element isn't received within the computed duration starting from its predecessor, the other observable sequence is used to produce future messages from that point on.
1560 /// </summary>
1561 /// <typeparam name="TSource">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>
1562 /// <typeparam name="TTimeout">The type of the elements in the timeout sequences used to indicate the timeout duration for each element in the source sequence.</typeparam>
1563 /// <param name="source">Source sequence to perform a timeout for.</param>
1564 /// <param name="timeoutDurationSelector">Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.</param>
1565 /// <param name="other">Sequence to return in case of a timeout.</param>
1566 /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>
1567 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="timeoutDurationSelector"/> or <paramref name="other"/> is null.</exception>
1568 public static IObservable<TSource> Timeout<TSource, TTimeout>(this IObservable<TSource> source, Func<TSource, IObservable<TTimeout>> timeoutDurationSelector, IObservable<TSource> other)
1569 {
1570 if (source == null)
1571 throw new ArgumentNullException("source");
1572 if (timeoutDurationSelector == null)
1573 throw new ArgumentNullException("timeoutDurationSelector");
1574 if (other == null)
1575 throw new ArgumentNullException("other");
1576
1577 return s_impl.Timeout<TSource, TTimeout>(source, timeoutDurationSelector, other);
1578 }
1579
1580 /// <summary>
1581 /// Applies a timeout policy to the observable sequence based on an initial timeout duration for the first element, and a timeout duration computed for each subsequent element.
1582 /// If the next element isn't received within the computed duration starting from its predecessor, a TimeoutException is propagated to the observer.
1583 /// </summary>
1584 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1585 /// <typeparam name="TTimeout">The type of the elements in the timeout sequences used to indicate the timeout duration for each element in the source sequence.</typeparam>
1586 /// <param name="source">Source sequence to perform a timeout for.</param>
1587 /// <param name="firstTimeout">Observable sequence that represents the timeout for the first element.</param>
1588 /// <param name="timeoutDurationSelector">Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.</param>
1589 /// <returns>The source sequence with a TimeoutException in case of a timeout.</returns>
1590 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="firstTimeout"/> or <paramref name="timeoutDurationSelector"/> is null.</exception>
1591 public static IObservable<TSource> Timeout<TSource, TTimeout>(this IObservable<TSource> source, IObservable<TTimeout> firstTimeout, Func<TSource, IObservable<TTimeout>> timeoutDurationSelector)
1592 {
1593 if (source == null)
1594 throw new ArgumentNullException("source");
1595 if (firstTimeout == null)
1596 throw new ArgumentNullException("firstTimeout");
1597 if (timeoutDurationSelector == null)
1598 throw new ArgumentNullException("timeoutDurationSelector");
1599
1600 return s_impl.Timeout<TSource, TTimeout>(source, firstTimeout, timeoutDurationSelector);
1601 }
1602
1603 /// <summary>
1604 /// Applies a timeout policy to the observable sequence based on an initial timeout duration for the first element, and a timeout duration computed for each subsequent element.
1605 /// If the next element isn't received within the computed duration starting from its predecessor, the other observable sequence is used to produce future messages from that point on.
1606 /// </summary>
1607 /// <typeparam name="TSource">The type of the elements in the source sequence and the other sequence used upon a timeout.</typeparam>
1608 /// <typeparam name="TTimeout">The type of the elements in the timeout sequences used to indicate the timeout duration for each element in the source sequence.</typeparam>
1609 /// <param name="source">Source sequence to perform a timeout for.</param>
1610 /// <param name="firstTimeout">Observable sequence that represents the timeout for the first element.</param>
1611 /// <param name="timeoutDurationSelector">Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.</param>
1612 /// <param name="other">Sequence to return in case of a timeout.</param>
1613 /// <returns>The source sequence switching to the other sequence in case of a timeout.</returns>
1614 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="firstTimeout"/> or <paramref name="timeoutDurationSelector"/> or <paramref name="other"/> is null.</exception>
1615 public static IObservable<TSource> Timeout<TSource, TTimeout>(this IObservable<TSource> source, IObservable<TTimeout> firstTimeout, Func<TSource, IObservable<TTimeout>> timeoutDurationSelector, IObservable<TSource> other)
1616 {
1617 if (source == null)
1618 throw new ArgumentNullException("source");
1619 if (firstTimeout == null)
1620 throw new ArgumentNullException("firstTimeout");
1621 if (timeoutDurationSelector == null)
1622 throw new ArgumentNullException("timeoutDurationSelector");
1623 if (other == null)
1624 throw new ArgumentNullException("other");
1625
1626 return s_impl.Timeout<TSource, TTimeout>(source, firstTimeout, timeoutDurationSelector, other);
1627 }
1628
1629 #endregion
1630
1631 #endregion
1632
1633 #region + Timer +
1634
1635 /// <summary>
1636 /// Returns an observable sequence that produces a single value after the specified relative due time has elapsed.
1637 /// </summary>
1638 /// <param name="dueTime">Relative time at which to produce the value. If this value is less than or equal to TimeSpan.Zero, the timer will fire as soon as possible.</param>
1639 /// <returns>An observable sequence that produces a value after the due time has elapsed.</returns>
1640 public static IObservable<long> Timer(TimeSpan dueTime)
1641 {
1642 return s_impl.Timer(dueTime);
1643 }
1644
1645 /// <summary>
1646 /// Returns an observable sequence that produces a single value at the specified absolute due time.
1647 /// </summary>
1648 /// <param name="dueTime">Absolute time at which to produce the value. If this value is less than or equal to DateTimeOffset.UtcNow, the timer will fire as soon as possible.</param>
1649 /// <returns>An observable sequence that produces a value at due time.</returns>
1650 public static IObservable<long> Timer(DateTimeOffset dueTime)
1651 {
1652 return s_impl.Timer(dueTime);
1653 }
1654
1655 /// <summary>
1656 /// Returns an observable sequence that periodically produces a value after the specified initial relative due time has elapsed.
1657 /// </summary>
1658 /// <param name="dueTime">Relative time at which to produce the first value. If this value is less than or equal to TimeSpan.Zero, the timer will fire as soon as possible.</param>
1659 /// <param name="period">Period to produce subsequent values. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>
1660 /// <returns>An observable sequence that produces a value after due time has elapsed and then after each period.</returns>
1661 /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
1662 public static IObservable<long> Timer(TimeSpan dueTime, TimeSpan period)
1663 {
1664 if (period < TimeSpan.Zero)
1665 throw new ArgumentOutOfRangeException("period");
1666
1667 return s_impl.Timer(dueTime, period);
1668 }
1669
1670 /// <summary>
1671 /// Returns an observable sequence that periodically produces a value starting at the specified initial absolute due time.
1672 /// </summary>
1673 /// <param name="dueTime">Absolute time at which to produce the first value. If this value is less than or equal to DateTimeOffset.UtcNow, the timer will fire as soon as possible.</param>
1674 /// <param name="period">Period to produce subsequent values. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>
1675 /// <returns>An observable sequence that produces a value at due time and then after each period.</returns>
1676 /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
1677 public static IObservable<long> Timer(DateTimeOffset dueTime, TimeSpan period)
1678 {
1679 if (period < TimeSpan.Zero)
1680 throw new ArgumentOutOfRangeException("period");
1681
1682 return s_impl.Timer(dueTime, period);
1683 }
1684
1685 /// <summary>
1686 /// Returns an observable sequence that produces a single value after the specified relative due time has elapsed, using the specified scheduler to run the timer.
1687 /// </summary>
1688 /// <param name="dueTime">Relative time at which to produce the value. If this value is less than or equal to TimeSpan.Zero, the timer will fire as soon as possible.</param>
1689 /// <param name="scheduler">Scheduler to run the timer on.</param>
1690 /// <returns>An observable sequence that produces a value after the due time has elapsed.</returns>
1691 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
1692 public static IObservable<long> Timer(TimeSpan dueTime, IScheduler scheduler)
1693 {
1694 if (scheduler == null)
1695 throw new ArgumentNullException("scheduler");
1696
1697 return s_impl.Timer(dueTime, scheduler);
1698 }
1699
1700 /// <summary>
1701 /// Returns an observable sequence that produces a single value at the specified absolute due time, using the specified scheduler to run the timer.
1702 /// </summary>
1703 /// <param name="dueTime">Absolute time at which to produce the value. If this value is less than or equal to DateTimeOffset.UtcNow, the timer will fire as soon as possible.</param>
1704 /// <param name="scheduler">Scheduler to run the timer on.</param>
1705 /// <returns>An observable sequence that produces a value at due time.</returns>
1706 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
1707 public static IObservable<long> Timer(DateTimeOffset dueTime, IScheduler scheduler)
1708 {
1709 if (scheduler == null)
1710 throw new ArgumentNullException("scheduler");
1711
1712 return s_impl.Timer(dueTime, scheduler);
1713 }
1714
1715 /// <summary>
1716 /// Returns an observable sequence that periodically produces a value after the specified initial relative due time has elapsed, using the specified scheduler to run timers.
1717 /// </summary>
1718 /// <param name="dueTime">Relative time at which to produce the first value. If this value is less than or equal to TimeSpan.Zero, the timer will fire as soon as possible.</param>
1719 /// <param name="period">Period to produce subsequent values. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>
1720 /// <param name="scheduler">Scheduler to run timers on.</param>
1721 /// <returns>An observable sequence that produces a value after due time has elapsed and then each period.</returns>
1722 /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
1723 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
1724 public static IObservable<long> Timer(TimeSpan dueTime, TimeSpan period, IScheduler scheduler)
1725 {
1726 if (period < TimeSpan.Zero)
1727 throw new ArgumentOutOfRangeException("period");
1728 if (scheduler == null)
1729 throw new ArgumentNullException("scheduler");
1730
1731 return s_impl.Timer(dueTime, period, scheduler);
1732 }
1733
1734 /// <summary>
1735 /// Returns an observable sequence that periodically produces a value starting at the specified initial absolute due time, using the specified scheduler to run timers.
1736 /// </summary>
1737 /// <param name="dueTime">Absolute time at which to produce the first value. If this value is less than or equal to DateTimeOffset.UtcNow, the timer will fire as soon as possible.</param>
1738 /// <param name="period">Period to produce subsequent values. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>
1739 /// <param name="scheduler">Scheduler to run timers on.</param>
1740 /// <returns>An observable sequence that produces a value at due time and then after each period.</returns>
1741 /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
1742 /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
1743 public static IObservable<long> Timer(DateTimeOffset dueTime, TimeSpan period, IScheduler scheduler)
1744 {
1745 if (period < TimeSpan.Zero)
1746 throw new ArgumentOutOfRangeException("period");
1747 if (scheduler == null)
1748 throw new ArgumentNullException("scheduler");
1749
1750 return s_impl.Timer(dueTime, period, scheduler);
1751 }
1752
1753 #endregion
1754
1755 #region + Timestamp +
1756
1757 /// <summary>
1758 /// Timestamps each element in an observable sequence using the local system clock.
1759 /// </summary>
1760 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1761 /// <param name="source">Source sequence to timestamp elements for.</param>
1762 /// <returns>An observable sequence with timestamp information on elements.</returns>
1763 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1764 public static IObservable<Timestamped<TSource>> Timestamp<TSource>(this IObservable<TSource> source)
1765 {
1766 if (source == null)
1767 throw new ArgumentNullException("source");
1768
1769 return s_impl.Timestamp<TSource>(source);
1770 }
1771
1772 /// <summary>
1773 /// Timestamp each element in an observable sequence using the clock of the specified scheduler.
1774 /// </summary>
1775 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1776 /// <param name="source">Source sequence to timestamp elements for.</param>
1777 /// <param name="scheduler">Scheduler used to compute timestamps.</param>
1778 /// <returns>An observable sequence with timestamp information on elements.</returns>
1779 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1780 public static IObservable<Timestamped<TSource>> Timestamp<TSource>(this IObservable<TSource> source, IScheduler scheduler)
1781 {
1782 if (source == null)
1783 throw new ArgumentNullException("source");
1784 if (scheduler == null)
1785 throw new ArgumentNullException("scheduler");
1786
1787 return s_impl.Timestamp<TSource>(source, scheduler);
1788 }
1789
1790 #endregion
1791
1792 #region + Window +
1793
1794 #region TimeSpan only
1795
1796 /// <summary>
1797 /// Projects each element of an observable sequence into consecutive non-overlapping windows which are produced based on timing information.
1798 /// </summary>
1799 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
1800 /// <param name="source">Source sequence to produce windows over.</param>
1801 /// <param name="timeSpan">Length of each window.</param>
1802 /// <returns>The sequence of windows.</returns>
1803 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1804 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
1805 /// <remarks>
1806 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.
1807 /// Because all source sequence elements end up in one of the windows, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced
1808 /// by the scheduler, where the action to close the current window and to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
1809 /// </remarks>
1810 public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan)
1811 {
1812 if (source == null)
1813 throw new ArgumentNullException("source");
1814 if (timeSpan < TimeSpan.Zero)
1815 throw new ArgumentOutOfRangeException("timeSpan");
1816
1817 return s_impl.Window<TSource>(source, timeSpan);
1818 }
1819
1820 /// <summary>
1821 /// Projects each element of an observable sequence into consecutive non-overlapping windows which are produced based on timing information, using the specified scheduler to run timers.
1822 /// </summary>
1823 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
1824 /// <param name="source">Source sequence to produce windows over.</param>
1825 /// <param name="timeSpan">Length of each window.</param>
1826 /// <param name="scheduler">Scheduler to run windowing timers on.</param>
1827 /// <returns>An observable sequence of windows.</returns>
1828 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1829 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
1830 /// <remarks>
1831 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.
1832 /// Because all source sequence elements end up in one of the windows, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced
1833 /// by the scheduler, where the action to close the current window and to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
1834 /// </remarks>
1835 public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, IScheduler scheduler)
1836 {
1837 if (source == null)
1838 throw new ArgumentNullException("source");
1839 if (timeSpan < TimeSpan.Zero)
1840 throw new ArgumentOutOfRangeException("timeSpan");
1841 if (scheduler == null)
1842 throw new ArgumentNullException("scheduler");
1843
1844 return s_impl.Window<TSource>(source, timeSpan, scheduler);
1845 }
1846
1847 /// <summary>
1848 /// Projects each element of an observable sequence into zero or more windows which are produced based on timing information.
1849 /// </summary>
1850 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
1851 /// <param name="source">Source sequence to produce windows over.</param>
1852 /// <param name="timeSpan">Length of each window.</param>
1853 /// <param name="timeShift">Interval between creation of consecutive windows.</param>
1854 /// <returns>An observable sequence of windows.</returns>
1855 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1856 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> or <paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
1857 /// <remarks>
1858 /// <para>
1859 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create windows with minimum duration
1860 /// length. However, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the
1861 /// current window may not execute immediately, despite the TimeSpan.Zero due time.
1862 /// </para>
1863 /// <para>
1864 /// Specifying a TimeSpan.Zero value for <paramref name="timeShift"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.
1865 /// However, this doesn't mean all windows will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler,
1866 /// where the action to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
1867 /// </para>
1868 /// </remarks>
1869 public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift)
1870 {
1871 if (source == null)
1872 throw new ArgumentNullException("source");
1873 if (timeSpan < TimeSpan.Zero)
1874 throw new ArgumentOutOfRangeException("timeSpan");
1875 if (timeShift < TimeSpan.Zero)
1876 throw new ArgumentOutOfRangeException("timeShift");
1877
1878 return s_impl.Window<TSource>(source, timeSpan, timeShift);
1879 }
1880
1881 /// <summary>
1882 /// Projects each element of an observable sequence into zero or more windows which are produced based on timing information, using the specified scheduler to run timers.
1883 /// </summary>
1884 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
1885 /// <param name="source">Source sequence to produce windows over.</param>
1886 /// <param name="timeSpan">Length of each window.</param>
1887 /// <param name="timeShift">Interval between creation of consecutive windows.</param>
1888 /// <param name="scheduler">Scheduler to run windowing timers on.</param>
1889 /// <returns>An observable sequence of windows.</returns>
1890 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1891 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> or <paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
1892 /// <remarks>
1893 /// <para>
1894 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create windows with minimum duration
1895 /// length. However, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the
1896 /// current window may not execute immediately, despite the TimeSpan.Zero due time.
1897 /// </para>
1898 /// <para>
1899 /// Specifying a TimeSpan.Zero value for <paramref name="timeShift"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.
1900 /// However, this doesn't mean all windows will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler,
1901 /// where the action to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
1902 /// </para>
1903 /// </remarks>
1904 public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift, IScheduler scheduler)
1905 {
1906 if (source == null)
1907 throw new ArgumentNullException("source");
1908 if (timeSpan < TimeSpan.Zero)
1909 throw new ArgumentOutOfRangeException("timeSpan");
1910 if (timeShift < TimeSpan.Zero)
1911 throw new ArgumentOutOfRangeException("timeShift");
1912 if (scheduler == null)
1913 throw new ArgumentNullException("scheduler");
1914
1915 return s_impl.Window<TSource>(source, timeSpan, timeShift, scheduler);
1916 }
1917
1918 #endregion
1919
1920 #region TimeSpan + int
1921
1922 /// <summary>
1923 /// Projects each element of an observable sequence into a window that is completed when either it's full or a given amount of time has elapsed.
1924 /// A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.
1925 /// </summary>
1926 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
1927 /// <param name="source">Source sequence to produce windows over.</param>
1928 /// <param name="timeSpan">Maximum time length of a window.</param>
1929 /// <param name="count">Maximum element count of a window.</param>
1930 /// <returns>An observable sequence of windows.</returns>
1931 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1932 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero. -or- <paramref name="count"/> is less than or equal to zero.</exception>
1933 /// <remarks>
1934 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.
1935 /// Because all source sequence elements end up in one of the windows, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced
1936 /// by the scheduler, where the action to close the current window and to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
1937 /// </remarks>
1938 public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count)
1939 {
1940 if (source == null)
1941 throw new ArgumentNullException("source");
1942 if (timeSpan < TimeSpan.Zero)
1943 throw new ArgumentOutOfRangeException("timeSpan");
1944 if (count <= 0)
1945 throw new ArgumentOutOfRangeException("count");
1946
1947 return s_impl.Window<TSource>(source, timeSpan, count);
1948 }
1949
1950 /// <summary>
1951 /// Projects each element of an observable sequence into a window that is completed when either it's full or a given amount of time has elapsed, using the specified scheduler to run timers.
1952 /// A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.
1953 /// </summary>
1954 /// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
1955 /// <param name="source">Source sequence to produce windows over.</param>
1956 /// <param name="timeSpan">Maximum time length of a window.</param>
1957 /// <param name="count">Maximum element count of a window.</param>
1958 /// <param name="scheduler">Scheduler to run windowing timers on.</param>
1959 /// <returns>An observable sequence of windows.</returns>
1960 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1961 /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> is less than TimeSpan.Zero. -or- <paramref name="count"/> is less than or equal to zero.</exception>
1962 /// <remarks>
1963 /// Specifying a TimeSpan.Zero value for <paramref name="timeSpan"/> is not recommended but supported, causing the scheduler to create windows as fast as it can.
1964 /// Because all source sequence elements end up in one of the windows, some windows won't have a zero time span. This is a side-effect of the asynchrony introduced
1965 /// by the scheduler, where the action to close the current window and to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
1966 /// </remarks>
1967 public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count, IScheduler scheduler)
1968 {
1969 if (source == null)
1970 throw new ArgumentNullException("source");
1971 if (timeSpan < TimeSpan.Zero)
1972 throw new ArgumentOutOfRangeException("timeSpan");
1973 if (count <= 0)
1974 throw new ArgumentOutOfRangeException("count");
1975 if (scheduler == null)
1976 throw new ArgumentNullException("scheduler");
1977
1978 return s_impl.Window<TSource>(source, timeSpan, count, scheduler);
1979 }
1980
1981 #endregion
1982
1983 #endregion
1984 }
1985 }