1
0
mirror of synced 2024-11-16 14:53:50 +00:00
Tapeti/Connection/TaskQueue.cs

25 lines
618 B
C#
Raw Normal View History

2016-11-17 16:33:27 +00:00
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Tapeti.Connection
{
public class TaskQueue
{
private readonly object previousTaskLock = new object();
private Task previousTask = Task.CompletedTask;
public Task Add(Action action)
{
lock (previousTaskLock)
{
previousTask = previousTask.ContinueWith(t => action(), CancellationToken.None
, TaskContinuationOptions.None
, TaskScheduler.Default);
return previousTask;
}
}
}
}