Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Async Interceptor/Invocation support #107
New method on ProxyGenerator:
Where IInterceptorAsync has one small difference:
In order for this to work all methodson the intercepted interface must return Task or Task < T > - this is a limitation that I think is accepted.
To generate IL for an async method is almost "impossible". So this is what I been thinking.
The AbstractInvocation gets two "helper" methods:
When generating the IL can check the return type of the method and call and return the result of the helper method like this:
Code to generate:
Is this something that could be added?
The change you're proposing is fairly large and I'd like to make sure it's absolutly necessary before we dive in and spend too much time on it.
I have added a small example interceptor to show the case that I have had problem with (this code works, but I have not been able to achive it with current implementation without add .Wait() which blocks that thread).
If the target is async, and as soon as it hits the first await it rolls out from Proceed. And it is not possible from the interceptor to change the return value (act on exception).
This is a failing test on existing codebase.
The problem is in the interceptor where I want to observe the result of the async method to be able to change the return value.
Yes, that works!
After analyzing the async code that my interceptor was generating, I could pin point the flaw. I was able to make a really nice solution to my problem thanks to the knowledge I picked up doing this PR.
There would be no real need to merge this PR as it is possible to work around it. However, I do think having async support in the Interceptor would be useful.
Thank you for spending time on this