Skip to content

Commit

Permalink
.ConfigureAwait() tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Nov 20, 2023
1 parent 062adc5 commit 02a358a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Agent/NewRelic/Agent/Core/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ public async Task TryInjectBrowserScriptAsync(string contentType, string request
if (rumBytes == null)
{
transaction.LogFinest("Skipping RUM Injection: No script was available.");
await baseStream.WriteAsync(buffer, 0, buffer.Length);
await baseStream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
}
else
await BrowserScriptInjectionHelper.InjectBrowserScriptAsync(buffer, baseStream, rumBytes, transaction);
await BrowserScriptInjectionHelper.InjectBrowserScriptAsync(buffer, baseStream, rumBytes, transaction).ConfigureAwait(false);
}

private string TryGetRUMScriptInternal(string contentType, string requestPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void OnPreCleanShutdown(PreCleanShutdownEvent obj)
if (!(uptime.TotalMilliseconds > _configuration.CollectorSendDataOnExitThreshold))
return;

Task.Run(HarvestAsync).GetAwaiter().GetResult();
Task.Run(HarvestAsync).Wait();
}

public override void Dispose()
Expand Down
3 changes: 3 additions & 0 deletions src/Agent/NewRelic/Agent/Core/AsyncSingleton.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Threading.Tasks;

namespace NewRelic.Agent.Core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static async Task InjectBrowserScriptAsync(byte[] buffer, Stream baseStre
{
// not found, can't inject anything
transaction?.LogFinest("Skipping RUM Injection: No suitable location found to inject script.");
await baseStream.WriteAsync(buffer, 0, buffer.Length);
await baseStream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
return;
}

Expand All @@ -34,13 +34,13 @@ public static async Task InjectBrowserScriptAsync(byte[] buffer, Stream baseStre
if (index < buffer.Length) // validate index is less than buffer length
{
// Write everything up to the insertion index
await baseStream.WriteAsync(buffer, 0, index);
await baseStream.WriteAsync(buffer, 0, index).ConfigureAwait(false);

// Write the RUM script
await baseStream.WriteAsync(rumBytes, 0, rumBytes.Length);
await baseStream.WriteAsync(rumBytes, 0, rumBytes.Length).ConfigureAwait(false);

// Write the rest of the doc, starting after the insertion index
await baseStream.WriteAsync(buffer, index, buffer.Length - index);
await baseStream.WriteAsync(buffer, index, buffer.Length - index).ConfigureAwait(false);
}
else
transaction?.LogFinest($"Skipping RUM Injection: Insertion index was invalid.");
Expand Down
2 changes: 1 addition & 1 deletion src/Agent/NewRelic/Agent/Core/Commands/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CommandService(IDataTransportService dataTransportService, IScheduler sch
_scheduler.ExecuteEvery(GetAndExecuteAgentCommandsAction, _configurationService.Configuration.GetAgentCommandsCycle);
}

private void GetAndExecuteAgentCommandsAction() => Task.Run(GetAndExecuteAgentCommandsAsync).GetAwaiter().GetResult();
private void GetAndExecuteAgentCommandsAction() => Task.Run(GetAndExecuteAgentCommandsAsync).Wait();

public override void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,17 @@ protected override void OnConfigurationUpdated(ConfigurationUpdateSource configu

private void OnStartAgent(StartAgentEvent eventData)
{
Task.Run(StartAsync).GetAwaiter().GetResult();
Task.Run(StartAsync).Wait();
}

private void OnRestartAgent(RestartAgentEvent eventData)
{
Task.Run(ReconnectAsync).GetAwaiter().GetResult();
Task.Run(ReconnectAsync).Wait();
}

private void OnCleanShutdown(CleanShutdownEvent eventData)
{
Task.Run(DisconnectAsync).GetAwaiter().GetResult();
Task.Run(DisconnectAsync).Wait();
}

#endregion Event handlers
Expand Down

0 comments on commit 02a358a

Please sign in to comment.