-
Notifications
You must be signed in to change notification settings - Fork 330
Closed
Description
Test code:
using System;
using System.Threading.Tasks;
using AspectCore.DynamicProxy;
namespace Program
{
public class Program
{
public class Intercept : AbstractInterceptorAttribute
{
public override Task Invoke(AspectContext context, AspectDelegate next)
{
context.Parameters[0] = "lemon";
return context.Invoke(next);
}
}
public interface IService
{
Task<string> GetValue(string val);
}
public class Service : IService
{
[Intercept]
public async Task<string> GetValue(string val)
{
await Task.Delay(3000);
return val;
}
}
static void Main(string[] args)
{
var builder = new ProxyGeneratorBuilder();
builder.Configure(_ => { });
var proxyGenerator = builder.Build();
var proxy = proxyGenerator.CreateInterfaceProxy<IService, Service>();
// IService proxy = new Service();
var val = proxy.GetValue("le");
Console.WriteLine("should return immediately");
Console.WriteLine(val.Result);
}
}
}Should print "should return immediately" immediately after GetValue, then sleep 3s and print the final result.
Problem lines:
| invoke.GetAwaiter().GetResult(); |
| task.GetAwaiter().GetResult(); |
| invoke.GetAwaiter().GetResult(); |
AspectCore-Framework/core/src/AspectCore.Core/DynamicProxy/AspectContext.Runtime.cs
Line 82 in a4c0c76
| AspectContextRuntimeExtensions.AwaitIfAsync(this, returnValue); |
| return typeof(Task).GetTypeInfo().IsTaskWithResult(); |
Reference:
https://stackoverflow.com/questions/17284517/is-task-result-the-same-as-getawaiter-getresult