| 1 |
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. |
| 2 |
|
| 3 |
#if HAS_AWAIT |
| 4 |
using System.Threading; |
| 5 |
using System.Reactive.Disposables; |
| 6 |
using System.Reactive.Subjects; |
| 7 |
|
| 8 |
namespace System.Reactive.Linq |
| 9 |
{ |
| 10 |
public static partial class Observable |
| 11 |
{ |
| 12 |
/// <summary> |
| 13 |
/// Gets an awaiter that returns the last value of the observable sequence or throws an exception if the sequence is empty. |
| 14 |
/// This operation subscribes to the observable sequence, making it hot. |
| 15 |
/// </summary> |
| 16 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 17 |
/// <param name="source">Source sequence to await.</param> |
| 18 |
/// <returns>Object that can be awaited.</returns> |
| 19 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 20 |
public static AsyncSubject<TSource> GetAwaiter<TSource>(this IObservable<TSource> source) |
| 21 |
{ |
| 22 |
if (source == null) |
| 23 |
throw new ArgumentNullException("source"); |
| 24 |
|
| 25 |
return s_impl.GetAwaiter<TSource>(source); |
| 26 |
} |
| 27 |
|
| 28 |
/// <summary> |
| 29 |
/// Gets an awaiter that returns the last value of the observable sequence or throws an exception if the sequence is empty. |
| 30 |
/// This operation subscribes and connects to the observable sequence, making it hot. |
| 31 |
/// </summary> |
| 32 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 33 |
/// <param name="source">Source sequence to await.</param> |
| 34 |
/// <returns>Object that can be awaited.</returns> |
| 35 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 36 |
public static AsyncSubject<TSource> GetAwaiter<TSource>(this IConnectableObservable<TSource> source) |
| 37 |
{ |
| 38 |
if (source == null) |
| 39 |
throw new ArgumentNullException("source"); |
| 40 |
|
| 41 |
return s_impl.GetAwaiter<TSource>(source); |
| 42 |
} |
| 43 |
|
| 44 |
/// <summary> |
| 45 |
/// Gets an awaiter that returns the last value of the observable sequence or throws an exception if the sequence is empty. |
| 46 |
/// This operation subscribes to the observable sequence, making it hot. The supplied CancellationToken can be used to cancel the subscription. |
| 47 |
/// </summary> |
| 48 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 49 |
/// <param name="source">Source sequence to await.</param> |
| 50 |
/// <param name="cancellationToken">Cancellation token.</param> |
| 51 |
/// <returns>Object that can be awaited.</returns> |
| 52 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 53 |
public static AsyncSubject<TSource> RunAsync<TSource>(this IObservable<TSource> source, CancellationToken cancellationToken) |
| 54 |
{ |
| 55 |
if (source == null) |
| 56 |
throw new ArgumentNullException("source"); |
| 57 |
|
| 58 |
return s_impl.RunAsync<TSource>(source, cancellationToken); |
| 59 |
} |
| 60 |
|
| 61 |
/// <summary> |
| 62 |
/// Gets an awaiter that returns the last value of the observable sequence or throws an exception if the sequence is empty. |
| 63 |
/// This operation subscribes and connects to the observable sequence, making it hot. The supplied CancellationToken can be used to cancel the subscription and connection. |
| 64 |
/// </summary> |
| 65 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 66 |
/// <param name="source">Source sequence to await.</param> |
| 67 |
/// <param name="cancellationToken">Cancellation token.</param> |
| 68 |
/// <returns>Object that can be awaited.</returns> |
| 69 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 70 |
public static AsyncSubject<TSource> RunAsync<TSource>(this IConnectableObservable<TSource> source, CancellationToken cancellationToken) |
| 71 |
{ |
| 72 |
if (source == null) |
| 73 |
throw new ArgumentNullException("source"); |
| 74 |
|
| 75 |
return s_impl.RunAsync<TSource>(source, cancellationToken); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
#endif |