Dematerialize.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. namespace System.Reactive.Linq
  5. {
  6. partial class AsyncObservable
  7. {
  8. public static IAsyncObservable<TSource> Dematerialize<TSource>(this IAsyncObservable<Notification<TSource>> source)
  9. {
  10. if (source == null)
  11. throw new ArgumentNullException(nameof(source));
  12. return Create<TSource>(observer => source.SubscribeSafeAsync(AsyncObserver.Dematerialize(observer)));
  13. }
  14. }
  15. partial class AsyncObserver
  16. {
  17. public static IAsyncObserver<Notification<TSource>> Dematerialize<TSource>(IAsyncObserver<TSource> observer)
  18. {
  19. if (observer == null)
  20. throw new ArgumentNullException(nameof(observer));
  21. return Create<Notification<TSource>>(
  22. n => n.AcceptAsync(observer),
  23. observer.OnErrorAsync,
  24. observer.OnCompletedAsync
  25. );
  26. }
  27. }
  28. }