1
0

Empty.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if !NO_PERF
  3. using System;
  4. using System.Reactive.Concurrency;
  5. namespace System.Reactive.Linq.ObservableImpl
  6. {
  7. class Empty<TResult> : Producer<TResult>
  8. {
  9. private readonly IScheduler _scheduler;
  10. public Empty(IScheduler scheduler)
  11. {
  12. _scheduler = scheduler;
  13. }
  14. protected override IDisposable Run(IObserver<TResult> observer, IDisposable cancel, Action<IDisposable> setSink)
  15. {
  16. var sink = new _(this, observer, cancel);
  17. setSink(sink);
  18. return sink.Run();
  19. }
  20. class _ : Sink<TResult>
  21. {
  22. private readonly Empty<TResult> _parent;
  23. public _(Empty<TResult> parent, IObserver<TResult> observer, IDisposable cancel)
  24. : base(observer, cancel)
  25. {
  26. _parent = parent;
  27. }
  28. public IDisposable Run()
  29. {
  30. return _parent._scheduler.Schedule(Invoke);
  31. }
  32. private void Invoke()
  33. {
  34. base._observer.OnCompleted();
  35. base.Dispose();
  36. }
  37. }
  38. }
  39. }
  40. #endif