Extensions.cs 1.6 KB

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