ToEvent.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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, _) =>
  14. {
  15. onNext(Unit.Default);
  16. return Task.CompletedTask;
  17. });
  18. }
  19. public static IEventSource<TSource> ToEvent<TSource>(this IAsyncObservable<TSource> source)
  20. {
  21. if (source == null)
  22. throw new ArgumentNullException(nameof(source));
  23. return new EventSource<TSource>(source, (onNext, x) =>
  24. {
  25. onNext(x);
  26. return Task.CompletedTask;
  27. });
  28. }
  29. }
  30. }