title: Convert any given function into an awaitable task
body: <p>The goal of the following code is to cast any given function into an awaitable function. The idea is to use it when fetching the data from the db, giving the code the flexibility to either use the synchronous fetch functions (an imposition of my current ORM), or use the very same functions as async.</p>
  
  <p>I am aware that there could be many things wrong with the concept behind code. By now I was just trying to get rid of the compiler errors so I can run the code and check the behavior. But of course I am open to discuss the concept beforehand, and if the whole idea behind it is wrong then use my time more efficiently looking for another solution.</p>
  
  <pre><code>async static void Main()
  {
      // The following line gives a compiler error:
      // Error    1   The best overloaded method match for 'CastFuncToTask&lt;int&gt;(System.Func&lt;int&gt;)' has some invalid arguments 
      int task = await CastFuncToTask&lt;int&gt;(TestFunc(2));
  }
  
  private static Task&lt;T&gt; CastFuncToTask&lt;T&gt;(Func&lt;T&gt; func)
  {
      TaskCompletionSource&lt;T&gt; taskCompletionSource = new TaskCompletionSource&lt;T&gt;();
      T result = func.Invoke();
      taskCompletionSource.SetResult(result);
      return taskCompletionSource.Task;
  }
  
  private static int TestFunc(int testInt) 
  {
      return testInt * 2;
  }
  </code></pre>