dotnet / dotNext

Next generation API for .NET
https://dotnet.github.io/dotNext/
MIT License
1.6k stars 119 forks source link

DotNext.Metaprogramming. Regression: worked in v 2.12.2, hangs in higher versions. #70

Closed ycherkes closed 3 years ago

ycherkes commented 3 years ago
public class Test
{
    [Fact]
    public async Task AsyncLambdaDoesntHangInTryBlock()
    {
        Expression<Func<Task<string>>> exprThrowException = () => ThrowException();
        Expression<Func<Task<string>>> exprReprocess = () => Reprocess();

        var asyncTryCatchExpression = AsyncLambda<Func<Task<string>>>(
            (lambdaContext, result) =>
            {
                Try(() =>
                    {

                        Assign(result, Expression.Invoke(exprThrowException).Await());
                        Return(result);
                    })
                    .Catch<Exception>(() =>
                    {
                        Assign(result, Expression.Invoke(exprReprocess).Await());
                        Return(result);
                    })
                    .End();
            });

        var asyncTryCatchFunc = asyncTryCatchExpression.Compile();
        var asyncTryCatchTask = asyncTryCatchFunc();

        var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
        await await Task.WhenAny(asyncTryCatchTask, Task.Delay(-1, cancellationTokenSource.Token));
    }

    private static async Task<string> ThrowException()
    {
        await Task.Delay(TimeSpan.FromSeconds(1));
        throw new Exception();
    }

    private static Task<string> Reprocess()
    {
        return Task.FromResult(string.Empty);
    }
}
sakno commented 3 years ago

@ycherkes , patch has been added to develop branch

ycherkes commented 3 years ago

@ycherkes , patch has been added to develop branch

Thank you. I can check it on my project code on Monday.

ycherkes commented 3 years ago

Hi @sakno, I've just checked the dev version in my project. Hangs are gone. When do you plan to release it?

sakno commented 3 years ago

I hope this evening.

ycherkes commented 3 years ago

I hope this evening.

I saw that version 3.2.0 was released. Thank you.