I implemented a custom async method builder but I have several questions for which i cannot find a proper answer.
1) I saw that depending on how i build (Debug / Release), the state machine gets compiled into a struct or a class. Is it possible to instruct the compiler to always generate a class no matter what?
2) I saw that the void SetStateMachine(IAsyncStateMachine m) is not called at all, even though in the documentation is says that, if the state machine is a struct, it should get called with a boxed version of it.
3) I made my method builder a class. Should I make it a struct? what is the best practice for this?
4) Strangely the GetAwaiter is sometimes called AFTER the builder.SetResult method is called. Is this a normal behavior? if we check the decompiled version of a Task, we can see clearly that it request first for an awaiter and if the awaiter is not completed, it calls the machine state AwaitOnCompleted / AwaitUnsafeOnCompleted.
Environment: .Net Core 2.1
Thanks a lot!