/// A collection of cancelable <see cref="TaskCompletionSource{T}"/> instances. Implementations must be threadsafe <b>and</b> must work correctly if the caller is holding a lock.
/// </summary>
/// <typeparam name="T">The type of the results. If this isn't needed, use <see cref="Object"/>.</typeparam>
publicinterfaceIAsyncWaitQueue<T>
{
/// <summary>
/// Gets whether the queue is empty.
/// </summary>
boolIsEmpty{get;}
/// <summary>
/// Creates a new entry and queues it to this wait queue. The returned task must support both synchronous and asynchronous waits.
/// </summary>
/// <returns>The queued task.</returns>
Task<T>Enqueue();
/// <summary>
/// Removes a single entry in the wait queue. Returns a disposable that completes that entry.
/// </summary>
/// <param name="result">The result used to complete the wait queue entry. If this isn't needed, use <c>default(T)</c>.</param>
IDisposableDequeue(Tresult=default(T));
/// <summary>
/// Removes all entries in the wait queue. Returns a disposable that completes all entries.
/// </summary>
/// <param name="result">The result used to complete the wait queue entries. If this isn't needed, use <c>default(T)</c>.</param>
IDisposableDequeueAll(Tresult=default(T));
/// <summary>
/// Attempts to remove an entry from the wait queue. Returns a disposable that cancels the entry.
/// </summary>
/// <param name="task">The task to cancel.</param>
/// <returns>A value indicating whether the entry was found and canceled.</returns>
IDisposableTryCancel(Tasktask);
/// <summary>
/// Removes all entries from the wait queue. Returns a disposable that cancels all entries.
/// </summary>
IDisposableCancelAll();
}
/// <summary>
/// Provides extension methods for wait queues.
/// </summary>
publicstaticclassAsyncWaitQueueExtensions
{
/// <summary>
/// Creates a new entry and queues it to this wait queue. If the cancellation token is already canceled, this method immediately returns a canceled task without modifying the wait queue.
/// </summary>
/// <param name="this">The wait queue.</param>
/// <param name="token">The token used to cancel the wait.</param>