Extensions.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Reactive.Concurrency;
  5. using System.Reactive.Disposables;
  6. using Microsoft.Reactive.Testing;
  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. scheduler.Schedule(action);
  23. else
  24. action();
  25. }
  26. public static IEnumerable<R> Zip<T1, T2, R>(this IEnumerable<T1> source1, IEnumerable<T2> source2, Func<T1, T2, R> f)
  27. {
  28. using (var e1 = source1.GetEnumerator())
  29. using (var e2 = source2.GetEnumerator())
  30. while (e1.MoveNext() && e2.MoveNext())
  31. yield return f(e1.Current, e2.Current);
  32. }
  33. }
  34. }