Skip to content

What does the DisposeAsync do in IAsyncEnumerable<T> #65294

Answered by John0King
John0King asked this question in Q&A
Discussion options

You must be logged in to vote

@huoyaoyuan @ufcpp @Clockwork-Muse @frankbolero

The generated code it too hard to read 🤣, but it seems that DisposeAsync will do nothing for user's code, it just make the state machine as finished like the yield break, that means you can not calling into your "clearn up" code when DisposeAsync

but when you use try{} finally{} block to wrap your code, then the code in finally block will be called , so when you calling DisposeAsync , the code inside the finally block will be execute.

I wasn't try insider try-finally block yet, but it should only work for the top level finally block

in fact, DisposeAsync will calling into finally but With One Exception :

> it = g.GetAsyncEnumerator();
> it.M…

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@John0King
Comment options

@Clockwork-Muse
Comment options

@John0King
Comment options

Comment options

You must be logged in to vote
2 replies
@Clockwork-Muse
Comment options

@John0King
Comment options

Comment options

You must be logged in to vote
1 reply
@John0King
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by John0King
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants