I found that we can create our own implementation of Task that can work with async and await. I know it would be bad Idea to create a custom implementation. But I want to know what things needs to be kept in mind while implementing MyTask
and MyTaskAwaiter
. I am looking for issues related to multithreading and deadlock.
//Example uses
public class MyApplicationClass
{
private MyTask GetResult()
{
return new MyTask();
}
public async Task MyExposedMethod()
{
//Here I can await on my custom task implementation.
await GetResult();
}
}
// My Custom Task. Instead of Task I will use MyTask
public struct MyTask
{
public MyTaskAwaiter GetAwaiter()
{
return new MyTaskAwaiter();
}
}
public struct MyTaskAwaiter : INotifyCompletion
{
public bool IsCompleted
{
get
{
throw new NotImplementedException();
}
}
public void GetResult()
{
throw new NotImplementedException();
}
public void OnCompleted(Action continuation)
{
throw new NotImplementedException();
}
}