title: What's the most concise way to create a Task that never returns?
body: <p>For testing purposes, I need to mock a <code>Task</code>-returning method on an interface handing back a task that never runs the continuation. Here's the code I have so far:</p>
  
  <pre><code>// FooTests.cs
  
  [Test]
  public void Foo()
  {
      var yielder = Substitute.For&lt;IYielder&gt;();
      yielder.YieldAsync().Returns(ThreadingUtilities.NeverReturningTask);
  
      ...
  }
  
  // ThreadingUtilities.cs
  
  using System.Diagnostics;
  using System.Threading.Tasks;
  
  namespace Repository.Editor.Android.UnitTests.TestInternal.Threading
  {
      internal static class ThreadingUtilities
      {
          public static Task NeverReturningTask { get; } = CreateNeverReturningTask();
  
          private async static Task CreateNeverReturningTask()
          {
              await new StopAwaitable();
              Debug.Fail("Execution shouldn't reach here.");
          }
      }
  }
  
  // StopAwaitable.cs
  
  using System;
  using System.Diagnostics;
  using System.Runtime.CompilerServices;
  
  namespace Repository.Editor.Android.UnitTests.TestInternal.Threading
  {
      internal struct StopAwaitable : INotifyCompletion
      {
          public bool IsCompleted =&gt; false;
  
          public StopAwaitable GetAwaiter() =&gt; this;
  
          public void GetResult()
          {
              Debug.Fail("The continuation shouldn't have been posted!");
          }
  
          public void OnCompleted(Action continuation)
          {
              // Ignore the continuation.
          }
      }
  }
  </code></pre>
  
  <p>Here, I've created a custom awaitable type that simply ignores the continuation handed to it-- <code>await new StopAwaitable()</code> has essentially the same effect as a <code>return</code> from a sync method. Then, I await it in an <code>async Task</code> method, creating a <code>Task</code> object that will never run the continuation.</p>
  
  <p>My question is, is this the most concise/clear way to do this? Is there any other way to create such a task that doesn't involve a custom awaitable, which will confuse people unfamiliar w/ how <code>async</code> works?</p>