Extensions.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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;
  5. using System.Collections.Generic;
  6. using System.Reactive.Concurrency;
  7. namespace ReactiveTests
  8. {
  9. public static class Extensions
  10. {
  11. //public static IDisposable ScheduleAbsolute(this TestScheduler scheduler, long time, Action action)
  12. //{
  13. // return scheduler.ScheduleAbsolute(default(object), time, (scheduler1, state1) => { action(); return Disposable.Empty; });
  14. //}
  15. //public static IDisposable ScheduleRelative(this TestScheduler scheduler, long time, Action action)
  16. //{
  17. // return scheduler.ScheduleRelative(default(object), time, (scheduler1, state1) => { action(); return Disposable.Empty; });
  18. //}
  19. public static void EnsureTrampoline(this CurrentThreadScheduler scheduler, Action action)
  20. {
  21. if (scheduler.ScheduleRequired)
  22. {
  23. scheduler.Schedule(action);
  24. }
  25. else
  26. {
  27. action();
  28. }
  29. }
  30. public static IEnumerable<R> Zip<T1, T2, R>(this IEnumerable<T1> source1, IEnumerable<T2> source2, Func<T1, T2, R> f)
  31. {
  32. using var e1 = source1.GetEnumerator();
  33. using var e2 = source2.GetEnumerator();
  34. while (e1.MoveNext() && e2.MoveNext())
  35. {
  36. yield return f(e1.Current, e2.Current);
  37. }
  38. }
  39. }
  40. }