Skip to content

Commit

Permalink
Use AsTask() (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored and Shane32 committed Oct 12, 2023
1 parent a22e1e0 commit 4911e52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/GraphQLParser/Visitors/SDLPrinterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public static string Print(this SDLPrinter printer, ASTNode node)
/// Prints the specified AST into the specified <see cref="StringBuilder"/> as a SDL document.
/// </summary>
public static void Print(this SDLPrinter printer, ASTNode node, StringBuilder stringBuilder)
#pragma warning disable CA2012 // Use ValueTasks correctly
=> printer.PrintAsync(node, new StringWriter(stringBuilder), default).GetAwaiter().GetResult();
#pragma warning restore CA2012 // Use ValueTasks correctly
=> printer.PrintAsync(node, new StringWriter(stringBuilder), default).AsTask().GetAwaiter().GetResult();

/// <summary>
/// Prints the specified AST into the specified <see cref="MemoryStream"/> as a SDL document.
Expand All @@ -33,9 +31,7 @@ public static void Print(this SDLPrinter printer, ASTNode node, StringBuilder st
public static void Print(this SDLPrinter printer, ASTNode node, MemoryStream memoryStream, Encoding? encoding = null)
{
using var streamWriter = new StreamWriter(memoryStream, encoding, -1 /* default */, true);
#pragma warning disable CA2012 // Use ValueTasks correctly
printer.PrintAsync(node, streamWriter, default).GetAwaiter().GetResult();
#pragma warning restore CA2012 // Use ValueTasks correctly
printer.PrintAsync(node, streamWriter, default).AsTask().GetAwaiter().GetResult();
// flush encoder state to stream
streamWriter.Flush();
}
Expand Down
4 changes: 1 addition & 3 deletions src/GraphQLParser/Visitors/SDLSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ private SDLSorter()
/// Nodes that have the same sort order will be retain their relative position.
/// </summary>
public static void Sort(ASTNode node, SDLSorterOptions? options = null)
#pragma warning disable CA2012 // Use ValueTasks correctly
=> _sorter.VisitAsync(node, options ?? SDLSorterOptions.Default).GetAwaiter().GetResult();
#pragma warning restore CA2012 // Use ValueTasks correctly
=> _sorter.VisitAsync(node, options ?? SDLSorterOptions.Default).AsTask().GetAwaiter().GetResult();

/// <inheritdoc/>
protected override ValueTask VisitAsync<T>(List<T>? nodes, SDLSorterOptions context)
Expand Down

0 comments on commit 4911e52

Please sign in to comment.