Empty.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #if !NO_PERF
  5. using System;
  6. using System.Reactive.Concurrency;
  7. namespace System.Reactive.Linq.ObservableImpl
  8. {
  9. class Empty<TResult> : Producer<TResult>
  10. {
  11. private readonly IScheduler _scheduler;
  12. public Empty(IScheduler scheduler)
  13. {
  14. _scheduler = scheduler;
  15. }
  16. protected override IDisposable Run(IObserver<TResult> observer, IDisposable cancel, Action<IDisposable> setSink)
  17. {
  18. var sink = new _(this, observer, cancel);
  19. setSink(sink);
  20. return sink.Run();
  21. }
  22. class _ : Sink<TResult>
  23. {
  24. private readonly Empty<TResult> _parent;
  25. public _(Empty<TResult> parent, IObserver<TResult> observer, IDisposable cancel)
  26. : base(observer, cancel)
  27. {
  28. _parent = parent;
  29. }
  30. public IDisposable Run()
  31. {
  32. return _parent._scheduler.Schedule(Invoke);
  33. }
  34. private void Invoke()
  35. {
  36. base._observer.OnCompleted();
  37. base.Dispose();
  38. }
  39. }
  40. }
  41. }
  42. #endif