Skip to content

Commit

Permalink
Merge pull request #162 from mono/async-main
Browse files Browse the repository at this point in the history
Use async main instead of sync-over-async
  • Loading branch information
mhutch committed Oct 2, 2023
2 parents 42747c5 + 857d4d0 commit 5e63517
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dotnet-t4/TextTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TextTemplating;

using Mono.Options;

namespace Mono.TextTemplating
Expand All @@ -36,10 +39,10 @@ sealed class TextTransform
{
static OptionSet optionSet;

public static int Main (string [] args)
public static async Task<int> Main (string [] args)
{
try {
return MainInternal (args);
return await MainInternal (args);
}
catch (Exception e) {
Console.Error.WriteLine (e);
Expand All @@ -56,7 +59,7 @@ public CustomOption (string prototype, string description, int count, Action<Opt
protected override void OnParseComplete (OptionContext c) => action (c.OptionValues);
}

static int MainInternal (string [] args)
static async Task<int> MainInternal (string [] args)
{
if (args.Length == 0 && !Console.IsInputRedirected) {
ShowHelp (true);
Expand Down Expand Up @@ -228,7 +231,7 @@ static int MainInternal (string [] args)

if (!generator.Errors.HasErrors) {
if (preprocessClassName == null) {
(outputFile, outputContent) = generator.ProcessTemplateAsync (pt, inputFile, inputContent, outputFile, settings).Result;
(outputFile, outputContent) = await generator.ProcessTemplateAsync (pt, inputFile, inputContent, outputFile, settings);
} else {
SplitClassName (preprocessClassName, settings);
outputContent = generator.PreprocessTemplate (pt, inputFile, inputContent, settings, out _);
Expand Down

0 comments on commit 5e63517

Please sign in to comment.