React to scheduler changes (#1846)

This commit is contained in:
Pavel Krymets 2017-05-18 14:49:48 -07:00 committed by GitHub
parent f8a6433cd5
commit 34ab089e7b
4 changed files with 16 additions and 9 deletions

View File

@ -33,9 +33,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
action(state); action(state);
} }
public void Schedule(Action action) public void Schedule(Action<object> action, object state)
{ {
Run(action); try
{
action(state);
}
catch (Exception e)
{
_log.LogError(0, e, "InlineLoggingThreadPool.Schedule");
}
} }
} }
} }

View File

@ -50,9 +50,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
ThreadPool.QueueUserWorkItem(action, state); ThreadPool.QueueUserWorkItem(action, state);
} }
public void Schedule(Action action) public void Schedule(Action<object> action, object state)
{ {
Run(action); Run(() => action(state));
} }
} }
} }

View File

@ -383,9 +383,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task; return await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false) == task;
} }
public void Schedule(Action action) public void Schedule(Action<object> action, object state)
{ {
Post(state => state(), action); Post(action, state);
} }
private struct Work private struct Work

View File

@ -114,9 +114,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var thread = new LibuvThread(transport); var thread = new LibuvThread(transport);
var mockScheduler = new Mock<IScheduler>(); var mockScheduler = new Mock<IScheduler>();
Action backPressure = null; Action backPressure = null;
mockScheduler.Setup(m => m.Schedule(It.IsAny<Action>())).Callback<Action>(a => mockScheduler.Setup(m => m.Schedule(It.IsAny<Action<object>>(), It.IsAny<object>())).Callback<Action<object>, object>((a, o) =>
{ {
backPressure = a; backPressure = () => a(o);
}); });
mockConnectionHandler.InputOptions.WriterScheduler = mockScheduler.Object; mockConnectionHandler.InputOptions.WriterScheduler = mockScheduler.Object;
mockConnectionHandler.OutputOptions.ReaderScheduler = thread; mockConnectionHandler.OutputOptions.ReaderScheduler = thread;