Program.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Reactive.Linq;
  3. using System.Reactive.Subjects;
  4. using System.Threading.Tasks;
  5. namespace Playground
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. MainAsync().GetAwaiter().GetResult();
  12. }
  13. static async Task MainAsync()
  14. {
  15. var subject = new SequentialSimpleAsyncSubject<int>();
  16. var res = subject.Where(x => x % 2 == 0).Select(x => x + 1);
  17. await res.SubscribeAsync(
  18. x =>
  19. {
  20. Console.WriteLine(x);
  21. return Task.CompletedTask;
  22. },
  23. ex =>
  24. {
  25. Console.WriteLine("Error: " + ex);
  26. return Task.CompletedTask;
  27. },
  28. () =>
  29. {
  30. Console.WriteLine("Completed");
  31. return Task.CompletedTask;
  32. }
  33. );
  34. for (var i = 0; i < 10; i++)
  35. {
  36. await subject.OnNextAsync(i);
  37. }
  38. await subject.OnCompletedAsync();
  39. }
  40. }
  41. }