Publish.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 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 Publish using ConcurrentSimpleAsyncSubject<T> underneath.
  9. partial class AsyncObservable
  10. {
  11. public static IAsyncObservable<TResult> Publish<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector)
  12. {
  13. if (source == null)
  14. throw new ArgumentNullException(nameof(source));
  15. if (selector == null)
  16. throw new ArgumentNullException(nameof(selector));
  17. return Multicast(source, () => new SequentialSimpleAsyncSubject<TSource>(), selector);
  18. }
  19. public static IAsyncObservable<TResult> Publish<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, Task<IAsyncObservable<TResult>>> selector)
  20. {
  21. if (source == null)
  22. throw new ArgumentNullException(nameof(source));
  23. if (selector == null)
  24. throw new ArgumentNullException(nameof(selector));
  25. return Multicast(source, () => Task.FromResult<IAsyncSubject<TSource, TSource>>(new SequentialSimpleAsyncSubject<TSource>()), selector);
  26. }
  27. }
  28. }