ToEvent.cs 924 B

123456789101112131415161718192021222324252627
  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.Threading.Tasks;
  5. namespace System.Reactive.Linq
  6. {
  7. partial class AsyncObservable
  8. {
  9. public static IEventSource<Unit> ToEvent<TSource>(this IAsyncObservable<Unit> source)
  10. {
  11. if (source == null)
  12. throw new ArgumentNullException(nameof(source));
  13. return new EventSource<Unit>(source, (onNext, _) => onNext(Unit.Default));
  14. }
  15. public static IEventSource<TSource> ToEvent<TSource>(this IAsyncObservable<TSource> source)
  16. {
  17. if (source == null)
  18. throw new ArgumentNullException(nameof(source));
  19. return new EventSource<TSource>(source, (onNext, x) => onNext(x));
  20. }
  21. }
  22. }