初始化上传
This commit is contained in:
28
常用工具集/Utility/Network/S7netplus/Internal/TaskQueue.cs
Normal file
28
常用工具集/Utility/Network/S7netplus/Internal/TaskQueue.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace S7.Net.Internal
|
||||
{
|
||||
internal class TaskQueue
|
||||
{
|
||||
private static readonly object Sentinel = new object();
|
||||
|
||||
private Task prev = Task.FromResult(Sentinel);
|
||||
|
||||
public async Task<T> Enqueue<T>(Func<Task<T>> action)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
await Interlocked.Exchange(ref prev, tcs.Task).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
return await action.Invoke().ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
tcs.SetResult(Sentinel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user