Commit 39a48f48 authored by Marc Gravell's avatar Marc Gravell

replace "async void" with F+F

parent 2f46249d
...@@ -153,10 +153,10 @@ public void OnMessage(Action<ChannelMessage> handler) ...@@ -153,10 +153,10 @@ public void OnMessage(Action<ChannelMessage> handler)
AssertOnMessage(handler); AssertOnMessage(handler);
ThreadPool.QueueUserWorkItem( ThreadPool.QueueUserWorkItem(
state => ((ChannelMessageQueue)state).OnMessageSyncImpl(), this); state => ((ChannelMessageQueue)state).OnMessageSyncImpl().RedisFireAndForget(), this);
} }
private async void OnMessageSyncImpl() private async Task OnMessageSyncImpl()
{ {
var handler = (Action<ChannelMessage>)_onMessageHandler; var handler = (Action<ChannelMessage>)_onMessageHandler;
while (!Completion.IsCompleted) while (!Completion.IsCompleted)
...@@ -184,10 +184,10 @@ public void OnMessage(Func<ChannelMessage, Task> handler) ...@@ -184,10 +184,10 @@ public void OnMessage(Func<ChannelMessage, Task> handler)
AssertOnMessage(handler); AssertOnMessage(handler);
ThreadPool.QueueUserWorkItem( ThreadPool.QueueUserWorkItem(
state => ((ChannelMessageQueue)state).OnMessageAsyncImpl(), this); state => ((ChannelMessageQueue)state).OnMessageAsyncImpl().RedisFireAndForget(), this);
} }
private async void OnMessageAsyncImpl() private async Task OnMessageAsyncImpl()
{ {
var handler = (Func<ChannelMessage, Task>)_onMessageHandler; var handler = (Func<ChannelMessage, Task>)_onMessageHandler;
while (!Completion.IsCompleted) while (!Completion.IsCompleted)
......
...@@ -857,10 +857,7 @@ public static ConnectionMultiplexer Connect(string configuration, TextWriter log ...@@ -857,10 +857,7 @@ public static ConnectionMultiplexer Connect(string configuration, TextWriter log
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> /// <param name="log">The <see cref="TextWriter"/> to log to.</param>
public static ConnectionMultiplexer Connect(ConfigurationOptions configuration, TextWriter log = null) public static ConnectionMultiplexer Connect(ConfigurationOptions configuration, TextWriter log = null)
{ {
using (ExecutionContext.IsFlowSuppressed() ? null : (AsyncFlowControl?)ExecutionContext.SuppressFlow()) return ConnectImpl(() => CreateMultiplexer(configuration), log);
{
return ConnectImpl(() => CreateMultiplexer(configuration), log);
}
} }
private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> multiplexerFactory, TextWriter log) private static ConnectionMultiplexer ConnectImpl(Func<ConnectionMultiplexer> multiplexerFactory, TextWriter log)
......
...@@ -22,7 +22,7 @@ public LoggingPipe(IDuplexPipe inner, string inPath, string outPath, SocketManag ...@@ -22,7 +22,7 @@ public LoggingPipe(IDuplexPipe inner, string inPath, string outPath, SocketManag
{ {
var pipe = new Pipe(mgr.ReceivePipeOptions); var pipe = new Pipe(mgr.ReceivePipeOptions);
Input = pipe.Reader; Input = pipe.Reader;
CloneAsync(inPath, inner.Input, pipe.Writer); CloneAsync(inPath, inner.Input, pipe.Writer).RedisFireAndForget();
} }
if (string.IsNullOrWhiteSpace(outPath)) if (string.IsNullOrWhiteSpace(outPath))
...@@ -33,12 +33,12 @@ public LoggingPipe(IDuplexPipe inner, string inPath, string outPath, SocketManag ...@@ -33,12 +33,12 @@ public LoggingPipe(IDuplexPipe inner, string inPath, string outPath, SocketManag
{ {
var pipe = new Pipe(mgr.SendPipeOptions); var pipe = new Pipe(mgr.SendPipeOptions);
Output = pipe.Writer; Output = pipe.Writer;
CloneAsync(outPath, pipe.Reader, inner.Output); CloneAsync(outPath, pipe.Reader, inner.Output).RedisFireAndForget();
} }
} }
private async void CloneAsync(string path, PipeReader from, PipeWriter to) private async Task CloneAsync(string path, PipeReader from, PipeWriter to)
{ {
try { try {
to.OnReaderCompleted((ex, o) => { to.OnReaderCompleted((ex, o) => {
......
...@@ -669,10 +669,7 @@ private PhysicalConnection GetConnection(TextWriter log) ...@@ -669,10 +669,7 @@ private PhysicalConnection GetConnection(TextWriter log)
// in that case PhysicalConnection will call back to PhysicalBridge, and most of PhysicalBridge methods assumes that physical is not null; // in that case PhysicalConnection will call back to PhysicalBridge, and most of PhysicalBridge methods assumes that physical is not null;
physical = new PhysicalConnection(this); physical = new PhysicalConnection(this);
using (ExecutionContext.IsFlowSuppressed() ? null : (AsyncFlowControl?)ExecutionContext.SuppressFlow()) physical.BeginConnectAsync(log).RedisFireAndForget();
{
physical.BeginConnectAsync(log);
}
} }
} }
return null; return null;
......
...@@ -72,7 +72,7 @@ public PhysicalConnection(PhysicalBridge bridge) ...@@ -72,7 +72,7 @@ public PhysicalConnection(PhysicalBridge bridge)
OnCreateEcho(); OnCreateEcho();
} }
internal async void BeginConnectAsync(TextWriter log) internal async Task BeginConnectAsync(TextWriter log)
{ {
Thread.VolatileWrite(ref firstUnansweredWriteTickCount, 0); Thread.VolatileWrite(ref firstUnansweredWriteTickCount, 0);
var bridge = BridgeCouldBeNull; var bridge = BridgeCouldBeNull;
...@@ -1301,7 +1301,7 @@ private void OnDebugAbort() ...@@ -1301,7 +1301,7 @@ private void OnDebugAbort()
partial void OnWrapForLogging(ref IDuplexPipe pipe, string name, SocketManager mgr); partial void OnWrapForLogging(ref IDuplexPipe pipe, string name, SocketManager mgr);
private async void ReadFromPipe() // yes it is an async void; deal with it! private async Task ReadFromPipe()
{ {
bool allowSyncRead = true, isReading = false; bool allowSyncRead = true, isReading = false;
try try
...@@ -1494,13 +1494,7 @@ private static RawResult ReadLineTerminatedString(ResultType type, ref BufferRea ...@@ -1494,13 +1494,7 @@ private static RawResult ReadLineTerminatedString(ResultType type, ref BufferRea
return new RawResult(type, payload, false); return new RawResult(type, payload, false);
} }
internal void StartReading() internal void StartReading() => ReadFromPipe().RedisFireAndForget();
{
using (ExecutionContext.IsFlowSuppressed() ? null : (AsyncFlowControl?)ExecutionContext.SuppressFlow())
{
ReadFromPipe();
}
}
internal static RawResult TryParseResult(in ReadOnlySequence<byte> buffer, ref BufferReader reader, internal static RawResult TryParseResult(in ReadOnlySequence<byte> buffer, ref BufferReader reader,
bool includeDetilInExceptions, ServerEndPoint server, bool allowInlineProtocol = false) bool includeDetilInExceptions, ServerEndPoint server, bool allowInlineProtocol = false)
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.88" /> <PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.90" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.5.0" /> <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.5.0" />
<PackageReference Include="System.IO.Pipelines" Version="4.5.0" /> <PackageReference Include="System.IO.Pipelines" Version="4.5.0" />
<PackageReference Include="System.Threading.Channels" Version="4.5.0" /> <PackageReference Include="System.Threading.Channels" Version="4.5.0" />
......
...@@ -29,6 +29,8 @@ public static Task<T> ObserveErrors<T>(this Task<T> task) ...@@ -29,6 +29,8 @@ public static Task<T> ObserveErrors<T>(this Task<T> task)
public static ConfiguredTaskAwaitable<T> ForAwait<T>(this Task<T> task) => task.ConfigureAwait(false); public static ConfiguredTaskAwaitable<T> ForAwait<T>(this Task<T> task) => task.ConfigureAwait(false);
public static ConfiguredValueTaskAwaitable<T> ForAwait<T>(this ValueTask<T> task) => task.ConfigureAwait(false); public static ConfiguredValueTaskAwaitable<T> ForAwait<T>(this ValueTask<T> task) => task.ConfigureAwait(false);
internal static void RedisFireAndForget(this Task task) => task?.ContinueWith(t => GC.KeepAlive(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
// Inspired from https://github.com/dotnet/corefx/blob/81a246f3adf1eece3d981f1d8bb8ae9de12de9c6/src/Common/tests/System/Threading/Tasks/TaskTimeoutExtensions.cs#L15-L43 // Inspired from https://github.com/dotnet/corefx/blob/81a246f3adf1eece3d981f1d8bb8ae9de12de9c6/src/Common/tests/System/Threading/Tasks/TaskTimeoutExtensions.cs#L15-L43
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment