Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support for ValueTask #105

Merged
merged 1 commit into from Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AssemblyToProcess/AssemblyToProcess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<ItemGroup>
<ProjectReference Include="..\ConfigureAwait\ConfigureAwait.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
</ItemGroup>
</Project>
76 changes: 76 additions & 0 deletions AssemblyToProcess/CatchAndFinally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,81 @@ public async Task Finally3()
await Task.Delay(1).ConfigureAwait(false);
}
}

#if NETCOREAPP2_0
public async Task Catch1_WithValueTask()
{
try
{
throw new NotImplementedException();
}
catch
{
await new ValueTask(Task.Delay(1));
}
}

[ConfigureAwait(false)]
public async Task Catch2_WithValueTask()
{
try
{
throw new NotImplementedException();
}
catch
{
await new ValueTask(Task.Delay(1));
}
}

public async Task Catch3_WithValueTask()
{
try
{
throw new NotImplementedException();
}
catch
{
await new ValueTask(Task.Delay(1)).ConfigureAwait(false);
}
}

public async Task Finally1_WithValueTask()
{
try
{
throw new NotImplementedException();
}
finally
{
await new ValueTask(Task.Delay(1));
}
}

[ConfigureAwait(false)]
public async Task Finally2_WithValueTask()
{
try
{
throw new NotImplementedException();
}
finally
{
await new ValueTask(Task.Delay(1));
}
}

public async Task Finally3_WithValueTask()
{
try
{
throw new NotImplementedException();
}
finally
{
await new ValueTask(Task.Delay(1)).ConfigureAwait(false);
}
}
#endif
}
}
27 changes: 27 additions & 0 deletions AssemblyToProcess/ClassWithAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,32 @@ public async Task<int> AsyncGenericMethodWithReturn(SynchronizationContext conte
SynchronizationContext.SetSynchronizationContext(context);
return await Task.Run(() => 10);
}

#if NETCOREAPP2_0
public async Task AsyncMethod_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Delay(10));
}

public async Task<int> AsyncMethodWithReturn_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Delay(10));
return 10;
}

public async Task AsyncGenericMethod_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Run(() => 10));
}

public async Task<int> AsyncGenericMethodWithReturn_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
return await new ValueTask<int>(Task.Run(() => 10));
}
#endif
}
}
27 changes: 27 additions & 0 deletions AssemblyToProcess/DoNotWeave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,32 @@ public async Task<int> AsyncGenericMethodWithReturn(SynchronizationContext conte
SynchronizationContext.SetSynchronizationContext(context);
return await Task.Run(() => 10).ConfigureAwait(true);
}

#if NETCOREAPP2_0
public async Task AsyncMethod_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Delay(10)).ConfigureAwait(true);
}

public async Task<int> AsyncMethodWithReturn_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Delay(10)).ConfigureAwait(true);
return 10;
}

public async Task AsyncGenericMethod_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Run(() => 10)).ConfigureAwait(true);
}

public async Task<int> AsyncGenericMethodWithReturn_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
return await new ValueTask<int>(Task.Run(() => 10)).ConfigureAwait(true);
}
#endif
}
}
93 changes: 93 additions & 0 deletions AssemblyToProcess/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,98 @@ public async Task<Example> AsyncMethod12()
var result = await Task.FromResult(new Example()).ConfigureAwait(false);
return result;
}

#if NETCOREAPP2_0
public async Task AsyncMethod1_WithValueTask()
{
await new ValueTask(Task.Delay(1));
}

[ConfigureAwait(false)]
public async Task AsyncMethod2_WithValueTask()
{
await new ValueTask(Task.Delay(1));
}

public async Task AsyncMethod3_WithValueTask()
{
await new ValueTask(Task.Delay(1)).ConfigureAwait(false);
}

public async Task<int> AsyncMethod4_WithValueTask()
{
var result = await new ValueTask<int>(Task.FromResult(10));
return result;
}

[ConfigureAwait(false)]
public async Task<int> AsyncMethod5_WithValueTask()
{
var result = await new ValueTask<int>(Task.FromResult(10));
return result;
}

public async Task<int> AsyncMethod6_WithValueTask()
{
var result = await new ValueTask<int>(Task.FromResult(10)).ConfigureAwait(false);
return result;
}

public async Task<int> AsyncMethod7_WithValueTask()
{
var count = await new ValueTask<int>(Task.FromResult(10));
var sum = 0;
for (var i = 0; i < count; i++)
{
await Task.Delay(1);
sum += await Task.FromResult(i);
}
return sum;
}

[ConfigureAwait(false)]
public async Task<int> AsyncMethod8_WithValueTask()
{
var count = await new ValueTask<int>(Task.FromResult(10));
var sum = 0;
for (var i = 0; i < count; i++)
{
await new ValueTask(Task.Delay(1));
sum += await new ValueTask<int>(Task.FromResult(i));
}
return sum;
}

public async Task<int> AsyncMethod9_WithValueTask()
{
var count = await new ValueTask<int>(Task.FromResult(10)).ConfigureAwait(false);
var sum = 0;
for (var i = 0; i < count; i++)
{
await new ValueTask(Task.Delay(1)).ConfigureAwait(false);
sum += await new ValueTask<int>(Task.FromResult(i)).ConfigureAwait(false);
}
return sum;
}

public async Task<Example> AsyncMethod10_WithValueTask()
{
var result = await new ValueTask<Example>(Task.FromResult(new Example()));
return result;
}

[ConfigureAwait(false)]
public async Task<Example> AsyncMethod11_WithValueTask()
{
var result = await new ValueTask<Example>(Task.FromResult(new Example()));
return result;
}

public async Task<Example> AsyncMethod12_WithValueTask()
{
var result = await new ValueTask<Example>(Task.FromResult(new Example())).ConfigureAwait(false);
return result;
}
#endif
}
}
16 changes: 16 additions & 0 deletions AssemblyToProcess/GenericIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ public async Task Method(Task<TItem> itemTask)
{
var item = await itemTask;
}

#if NETCOREAPP2_0
[ConfigureAwait(false)]
public async Task Method_WithValueTask(Task<TItem> itemTask)
{
var item = await new ValueTask<TItem>(itemTask);
}
#endif
}

sealed class GenericMethod
Expand All @@ -20,5 +28,13 @@ public async Task Method<TItem>(Task<TItem> itemTask)
{
var item = await itemTask;
}

#if NETCOREAPP2_0
[ConfigureAwait(false)]
public async Task Method_WithValueTask<TItem>(Task<TItem> itemTask)
{
var item = await new ValueTask<TItem>(itemTask);
}
#endif
}
}
12 changes: 12 additions & 0 deletions AssemblyToProcess/Issue1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@ async Task WithReaderAndWriter(TextWriter writer, StreamReader reader)
await writer.WriteLineAsync(line);
}
}

#if NETCOREAPP2_0
[ConfigureAwait(false)]
async Task WithReaderAndWriter_WithValueTask(TextWriter writer, StreamReader reader)
{
string line;
while ((line = await new ValueTask<string>(reader.ReadLineAsync())) != null)
{
await new ValueTask(writer.WriteLineAsync(line));
}
}
#endif
}
}
9 changes: 9 additions & 0 deletions AssemblyToProcess/MethodWithAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ public async Task AsyncMethod(SynchronizationContext context)
SynchronizationContext.SetSynchronizationContext(context);
await Task.Delay(0);
}

#if NETCOREAPP2_0
[ConfigureAwait(false)]
public async Task AsyncMethod_WithValueTask(SynchronizationContext context)
{
SynchronizationContext.SetSynchronizationContext(context);
await new ValueTask(Task.Delay(0));
}
#endif
}
}
14 changes: 14 additions & 0 deletions AssemblyToProcess/MethodWithUsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ static async Task<IDisposable> NewMethod()
await Task.Delay(0);
return new MyDisposable();
}

#if NETCOREAPP2_0
[ConfigureAwait(false)]
public async Task AsyncMethod_WithValueTask()
{
using(await new ValueTask<IDisposable>(NewMethod_WithValueTask())){}
}

static async Task<IDisposable> NewMethod_WithValueTask()
{
await new ValueTask(Task.Delay(0));
return new MyDisposable();
}
#endif
}

public class MyDisposable : IDisposable
Expand Down
Loading