title: How do I create a scheduler which never executes more than one Task at a time using async-await?
body: <p>I want to implement a class or pattern that ensures that I never execute more than one Task at a time for a certain set of operations (HTTP calls). The invocations of the Tasks can come from different threads at random times. I want to make use of the async-await pattern so that the caller can handle exceptions by wrapping the call in a try-catch. </p>
  
  <p>Here's an illustration of the intended flow of execution:</p>
  
  <p><img src="https://i.stack.imgur.com/EVlx3.png" alt="enter image description here"></p>
  
  <p>Pseudo code from caller:</p>
  
  <pre><code>try {
      Task someTask = GetTask();
      await SomeScheduler.ThrottledRun(someTask);
  } 
  catch(Exception ex) { 
      // Handle exception
  }
  </code></pre>
  
  <p>The <code>Task</code>class here might instead be an <code>Action</code> class depending on the solution.</p>
  
  <p>Note that I when I use the word "Schedule" in this question I'm not necessarily using it with relation to the <a href="http://msdn.microsoft.com/en-us/library/dd997402.aspx" rel="noreferrer">.NET Task Scheduler</a>. I don't know the async-await library well enough to know at what angle and with what tools to approach this problem. The TaskScheduler might be relevant here, and it may not. I've read the <a href="http://www.microsoft.com/en-us/download/confirmation.aspx?id=19957" rel="noreferrer">TAP pattern</a> document and found patterns that almost solve this problem, but not quite (the chapter on interleaving).</p>