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);
}
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

@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
_log = log;
// Curry and capture log in closures once
// The currying is done in functions of the same name to improve the
// The currying is done in functions of the same name to improve the
// call stack for exceptions and profiling else it shows up as LoggingThreadPool.ctor>b__4_0
// and you aren't sure which of the 3 functions was called.
RunAction();
@ -50,9 +50,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
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;
}
public void Schedule(Action action)
public void Schedule(Action<object> action, object state)
{
Post(state => state(), action);
Post(action, state);
}
private struct Work

View File

@ -114,9 +114,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
var thread = new LibuvThread(transport);
var mockScheduler = new Mock<IScheduler>();
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.OutputOptions.ReaderScheduler = thread;