Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. public class ConsumerTimeoutFilter<T> : IFilter<T> where T : class, PipeContext
  2. {
  3. private readonly TimeSpan timeout;
  4.  
  5. public ConsumerTimeoutFilter(TimeSpan timeout)
  6. {
  7. this.timeout = timeout;
  8. }
  9.  
  10. public Task Send(T context, IPipe<T> next)
  11. {
  12. var source = new CancellationTokenSource();
  13. var task = Task.Run(() => next.Send(context), source.Token);
  14. source.CancelAfter(timeout);
  15. return task;
  16. }
  17.  
  18. public void Probe(ProbeContext context)
  19. {
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement