Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Apr 15, 2018
1 parent fc8b34f commit fff8dad
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions AsyncFileWriterTester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ await handler(async s =>
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
try
{
await sw.WriteAsync(s);
await sw.WriteAsync(s).ConfigureAwait(false);
}
finally
{
Expand All @@ -50,8 +50,8 @@ await handler(async s =>
});

// FlushAsync here rather than block in Dispose on Flush
await sw.FlushAsync();
await fs.FlushAsync();
await sw.FlushAsync().ConfigureAwait(false);
await fs.FlushAsync().ConfigureAwait(false);
}
});
}
Expand All @@ -66,11 +66,11 @@ await handler(async s =>
using (var fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Write, bufferSize: 4096 * 4, useAsync: true))
using (var sw = new StreamWriter(fs))
{
await sw.WriteAsync(s);
await sw.WriteAsync(s).ConfigureAwait(false);

// FlushAsync here rather than block in Dispose on Flush
await sw.FlushAsync();
await fs.FlushAsync();
await sw.FlushAsync().ConfigureAwait(false);
await fs.FlushAsync().ConfigureAwait(false);
}
});
});
Expand Down Expand Up @@ -116,7 +116,7 @@ static async Task TestAsync(Func<string, Func<Func<string, Task>, Task>, Task> c

Console.WriteLine($"Total Time: {sw.Elapsed.TotalSeconds} seconds");
Console.WriteLine($"Total Bytes: {Counter.Aggregate((b, c) => new Telemetry() { Bytes = b.Bytes + c.Bytes }).Bytes:#,##0}");
Console.WriteLine($"Total Blocking Time: {Counter.Aggregate((b, c) => new Telemetry() { Time = b.Time + c.Time }).Time}");
Console.WriteLine($"Total Wait Time: {Counter.Aggregate((b, c) => new Telemetry() { Time = b.Time + c.Time }).Time}");
Console.WriteLine("------------------------");
Console.WriteLine();
}
Expand All @@ -137,11 +137,11 @@ static async Task RunAsync(Func<string, Task> asyncHandler)
//Console.WriteLine("Total Posted: {0:#,##0}", count);
}

static async Task WriteAsync(int i, Func<string, Task> s)
static async Task WriteAsync(int i, Func<string, Task> asyncHandler)
{
var message = $"{i}) {DateTime.Now}\n 00000000000000000000000000000000111111111111111111111111111222222222222222222222222222";
var t = Stopwatch.StartNew();
await s(message).ConfigureAwait(false);
await asyncHandler(message).ConfigureAwait(false);
t.Stop();
Counter.Add(new Telemetry() { Time = t.Elapsed, Bytes = message.Length });
Interlocked.Increment(ref count);
Expand Down

0 comments on commit fff8dad

Please sign in to comment.