I am trying to create a class that lets me call methods with a specified timout. I have the actual timeout implementation working, but am having trouble encapsulating this into a class successfully.
I have decided at this time to limit myself to working with just the 5 Action delegates to put a timeout on methods that take 0 - 4 arguments. For the purposes of this question i will use the one argument variant of Action.
My Ideal calling syntax would be something like this:
Action<int> a = new TimeoutAction(i => i + 1)
{
Timeout = Timespan.FromSeconds(10)
}
or this:
Action<int> a = (x => x + 1).Timeout(Timespan.FromSeconds(10))
I am almost sure that the first version isnt possible as there is no way to inherit from a delegate. The second may be possible by using an extension method on the Delegate
type.
A final fallback would be to create static methods that take in the appropriate delegate type and return a Delegate with the same signature but with the timeouts included.
Any suggestions or ideas?