title: Retry policy within ITargetBlock<TInput>
body: <p>I need to introduce a retry policy to the workflow. Let's say there are 3 blocks that are connected in such a way:</p>
  
  <pre><code>var executionOptions = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 3 };
  var buffer = new BufferBlock&lt;int&gt;();
  var processing = new TransformBlock&lt;int, int&gt;(..., executionOptions);
  var send = new ActionBlock&lt;int&gt;(...);
  
  buffer.LinkTo(processing);
  processing.LinkTo(send);
  </code></pre>
  
  <p>So there is a buffer which accumulates data, then send it to the transform block that processes not more that 3 items at one time, and then the result send to the action block.</p>
  
  <p>Potentially during processing the transform block transient errors are possible, and I want retry the block if the error is transient for several times.</p>
  
  <p>I know that blocks generally are not retryable (delegates that passed into the blocks could be made retryable). And one of the options is to wrap the delegate passed to support retrying.</p>
  
  <p>I also know that there is a very good library <a href="http://nuget.org/packages/TransientFaultHandling.Core" rel="noreferrer"><code>TransientFaultHandling.Core</code></a> that provides the retry mechanisms to transient faults. This is an excellent library but not in my case. If I wrap the delegate that is passed to the transform block into the <code>RetryPolicy.ExecuteAsync</code> method, the <em>message</em> inside the transform block will be locked, and until retry either completes or fails, the transform block won't be able to receive a new message. Imagine, if all the 3 messages are entered into the retrying (let's say, the next retry attempt will be in 2 minutes) and fail, the transform block will be stuck until at least one message leave the transform block.</p>
  
  <p>The only solution I see is to extend the <code>TranformBlock</code> (actually, <code>ITargetBlock</code> will be enough too), and do the retry manually (like from <a href="https://stackoverflow.com/a/1563234/102112">here</a>):</p>
  
  <pre><code>do
   {
      try { return await transform(input); }
      catch
      { 
          if( numRetries &lt;= 0 ) throw;
          else Task.Delay(timeout).ContinueWith(t =&gt; processing.Post(message));
      }
   } while( numRetries-- &gt; 0 );
  </code></pre>
  
  <p>i.g. to put the message inside the transform block again with a delay, but in this case the retry context (number of retries left, etc.) also should be passed into this block. Sounds too complex...</p>
  
  <p>Does anyone see a simpler approach to implement retry policy for a workflow block?</p>