-Async cleanup

This commit is contained in:
James Newton-King
2017-09-03 10:43:14 +12:00
parent 87d9010a20
commit fe2ec84c18
3 changed files with 9 additions and 27 deletions
+2 -20
View File
@@ -47,7 +47,7 @@ namespace Newtonsoft.Json.Linq
var t = writer.WriteStartObjectAsync(cancellationToken);
if (!t.IsCompletedSucessfully())
{
return AwaitStartObject(t, writer, cancellationToken, converters);
return AwaitProperties(t, 0, writer, cancellationToken, converters);
}
for (int i = 0; i < _properties.Count; i++)
@@ -59,22 +59,9 @@ namespace Newtonsoft.Json.Linq
}
}
t = writer.WriteEndObjectAsync(cancellationToken);
return (t.IsCompletedSucessfully()) ? AsyncUtils.CompletedTask : AwaitEndObject(t);
return writer.WriteEndObjectAsync(cancellationToken);
// Local functions, params renamed (capitalized) so as not to capture and allocate when calling async
async Task AwaitStartObject(Task task, JsonWriter Writer, CancellationToken CancellationToken, JsonConverter[] Converters)
{
await task.ConfigureAwait(false);
for (int i = 0; i < _properties.Count; i++)
{
await _properties[i].WriteToAsync(Writer, CancellationToken, Converters).ConfigureAwait(false);
}
await Writer.WriteEndObjectAsync(CancellationToken).ConfigureAwait(false);
}
async Task AwaitProperties(Task task, int i, JsonWriter Writer, CancellationToken CancellationToken, JsonConverter[] Converters)
{
await task.ConfigureAwait(false);
@@ -85,11 +72,6 @@ namespace Newtonsoft.Json.Linq
await Writer.WriteEndObjectAsync(CancellationToken).ConfigureAwait(false);
}
async Task AwaitEndObject(Task task)
{
await task.ConfigureAwait(false);
}
}
/// <summary>