Skip to content

Commit 3d82f8c

Browse files
committed
Support await ValueTask
1 parent 9f62f36 commit 3d82f8c

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

sandbox/SingleContainedApp/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using ConsoleAppFramework;
1+
#pragma warning disable CS1998
2+
3+
using ConsoleAppFramework;
24
using ConsoleAppFramework.Logging;
35
using Microsoft.Extensions.Configuration;
46
using Microsoft.Extensions.DependencyInjection;
@@ -158,12 +160,16 @@ public async Task Throw()
158160

159161
public class SimpleTwoArgs : ConsoleAppBase
160162
{
161-
public void Hello(
162-
string name,
163-
int repeat)
163+
public async ValueTask<int> Hello(string name, int repeat)
164164
{
165165
Context.Logger.LogInformation($"name:{name}");
166+
167+
Context.Logger.LogInformation($"Wait {repeat} Seconds.");
168+
await Task.Delay(TimeSpan.FromSeconds(repeat));
169+
166170
Context.Logger.LogInformation($"repeat:{repeat}");
171+
172+
return 100;
167173
}
168174
}
169175

@@ -173,6 +179,8 @@ static async Task Main(string[] args)
173179
{
174180
//args = new[] { "-array", "10,20,30", "-person", @"{""Age"":10,""Name"":""foo""}" };
175181

182+
args = new[] { "-name", "aaa", "-repeat", "3" };
183+
176184

177185
await Host.CreateDefaultBuilder()
178186
.ConfigureLogging(logging =>

src/ConsoleAppFramework/ConsoleAppEngine.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ async Task RunCore(ConsoleAppContext ctx, Type type, MethodInfo methodInfo, stri
162162
case Task task:
163163
await task;
164164
break;
165+
case ValueTask<int> valueTaskWithExitCode:
166+
Environment.ExitCode = await valueTaskWithExitCode;
167+
break;
168+
case ValueTask valueTask:
169+
await valueTask;
170+
break;
165171
}
166172
}
167173
catch (Exception ex)

tests/ConsoleAppFramework.Integration.Test/ConsoleAppFramework.Integration.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
5-
5+
<Nullable>enable</Nullable>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

0 commit comments

Comments
 (0)