1
0

PublishLast.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Reactive.Subjects;
  5. using System.Threading.Tasks;
  6. namespace System.Reactive.Linq
  7. {
  8. // REVIEW: Expose PublishLast using ConcurrentAsyncAsyncSubject<T> underneath.
  9. public partial class AsyncObservable
  10. {
  11. public static IConnectableAsyncObservable<TSource> PublishLast<TSource>(this IAsyncObservable<TSource> source)
  12. {
  13. if (source == null)
  14. throw new ArgumentNullException(nameof(source));
  15. return Multicast(source, new SequentialAsyncAsyncSubject<TSource>());
  16. }
  17. public static IAsyncObservable<TResult> PublishLast<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector)
  18. {
  19. if (source == null)
  20. throw new ArgumentNullException(nameof(source));
  21. if (selector == null)
  22. throw new ArgumentNullException(nameof(selector));
  23. return Multicast(source, () => new SequentialAsyncAsyncSubject<TSource>(), selector);
  24. }
  25. public static IAsyncObservable<TResult> PublishLast<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, ValueTask<IAsyncObservable<TResult>>> selector)
  26. {
  27. if (source == null)
  28. throw new ArgumentNullException(nameof(source));
  29. if (selector == null)
  30. throw new ArgumentNullException(nameof(selector));
  31. return Multicast(source, () => new ValueTask<IAsyncSubject<TSource, TSource>>(new SequentialAsyncAsyncSubject<TSource>()), selector);
  32. }
  33. }
  34. }