using System.Collections.Generic; using System.Threading.Tasks; namespace MQTTnet.Core.Internal { public sealed class AsyncGate { private readonly Queue> _waitingTasks = new Queue>(); public Task WaitOneAsync() { var tcs = new TaskCompletionSource(); lock (_waitingTasks) { _waitingTasks.Enqueue(tcs); } return tcs.Task; } public void Set() { lock (_waitingTasks) { if (_waitingTasks.Count > 0) { _waitingTasks.Dequeue().SetResult(true); } } } } }