AsyncPlan.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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.Collections.Generic;
  5. using System.Threading.Tasks;
  6. namespace System.Reactive.Joins
  7. {
  8. public abstract class AsyncPlan<TResult>
  9. {
  10. internal AsyncPlan()
  11. {
  12. }
  13. internal abstract ActiveAsyncPlan Activate(Dictionary<object, IAsyncJoinObserver> externalSubscriptions, IAsyncObserver<TResult> observer, Func<ActiveAsyncPlan, Task> deactivate);
  14. internal static AsyncJoinObserver<TSource> CreateObserver<TSource>(Dictionary<object, IAsyncJoinObserver> externalSubscriptions, IAsyncObservable<TSource> observable, Func<Exception, Task> onError)
  15. {
  16. var res = default(AsyncJoinObserver<TSource>);
  17. if (externalSubscriptions.TryGetValue(observable, out var joinObserver))
  18. {
  19. res = (AsyncJoinObserver<TSource>)joinObserver;
  20. }
  21. else
  22. {
  23. res = new AsyncJoinObserver<TSource>(observable, onError);
  24. externalSubscriptions.Add(observable, res);
  25. }
  26. return res;
  27. }
  28. }
  29. }