Skip to content

Commit

Permalink
Give up on Thread Locals, synchronize use of overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Feb 24, 2012
1 parent d705835 commit 460fcbd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ReactiveUI.Testing/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reactive;
using System.Reactive.Disposables;
using System.Threading;
using Microsoft.Reactive.Testing;
using ReactiveUI;
using System.Reactive.Concurrency;
Expand All @@ -9,6 +10,9 @@ namespace ReactiveUI.Testing
{
public static class TestUtils
{
static readonly object schedGate = 42;
static readonly object mbGate = 42;

/// <summary>
/// WithScheduler overrides the default Deferred and Taskpool schedulers
/// with the given scheduler until the return value is disposed. This
Expand All @@ -20,6 +24,7 @@ public static class TestUtils
/// schedulers.</returns>
public static IDisposable WithScheduler(IScheduler sched)
{
Monitor.Enter(schedGate);
var prevDef = RxApp.DeferredScheduler;
var prevTask = RxApp.TaskpoolScheduler;

Expand All @@ -29,6 +34,7 @@ public static IDisposable WithScheduler(IScheduler sched)
return Disposable.Create(() => {
RxApp.DeferredScheduler = prevDef;
RxApp.TaskpoolScheduler = prevTask;
Monitor.Exit(schedGate);
});
}

Expand Down Expand Up @@ -103,8 +109,13 @@ public static IDisposable WithMessageBus(this TestScheduler sched, IMessageBus m
{
var origMessageBus = RxApp.MessageBus;

Monitor.Enter(mbGate);
RxApp.MessageBus = messageBus ?? new MessageBus();
return Disposable.Create(() => RxApp.MessageBus = origMessageBus);
return Disposable.Create(() =>
{
RxApp.MessageBus = origMessageBus;
Monitor.Exit(mbGate);
});
}

/// <summary>
Expand Down

0 comments on commit 460fcbd

Please sign in to comment.