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

IUniTaskAsyncEnumerator DisposeAsync does not run finally blocks #438

Closed
timcassell opened this issue Jan 25, 2023 · 2 comments
Closed

IUniTaskAsyncEnumerator DisposeAsync does not run finally blocks #438

timcassell opened this issue Jan 25, 2023 · 2 comments
Labels

Comments

@timcassell
Copy link

If an await foreach loop is canceled with the break keyword, the DisposeAsync should run any finally blocks within the method body. But it does not.

static IUniTaskAsyncEnumerable<int> IterateAsync()
{
    return UniTaskAsyncEnumerable.Create<int>(async (writer, _) =>
    {
        try
        {
            await writer.YieldAsync(0);
        }
        finally
        {
            Console.WriteLine("Finally block"); // Never executes.
        }
    });
}
await foreach (var elem in IterateAsync())
{
    Console.WriteLine("elem: " + elem);
    break;
}

Compare to C# 8 async IAsyncEnumerable, which works:

static async IAsyncEnumerable<int> IterateAsync()
{
    try
    {
        yield return 0;
    }
    finally
    {
        Console.WriteLine("Finally block");
    }
}
@timcassell timcassell changed the title UniTaskAsyncEnumerator DisposeAsync is not implemented properly UniTaskAsyncEnumerator DisposeAsync does not run finally blocks Jan 25, 2023
@timcassell timcassell changed the title UniTaskAsyncEnumerator DisposeAsync does not run finally blocks IUniTaskAsyncEnumerator DisposeAsync does not run finally blocks Jan 26, 2023
@github-actions
Copy link
Contributor

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@hadashiA
Copy link
Contributor

Fixed in #484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants