本文整理汇总了C#中AsyncQueue.DequeueAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue.DequeueAsync方法的具体用法?C# AsyncQueue.DequeueAsync怎么用?C# AsyncQueue.DequeueAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncQueue
的用法示例。
在下文中一共展示了AsyncQueue.DequeueAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Items_should_be_dequeued_in_the_order_they_were_enqueued_2
public void Items_should_be_dequeued_in_the_order_they_were_enqueued_2()
{
var subject = new AsyncQueue<int>();
var result = subject.DequeueAsync(CancellationToken.None);
var result2 = subject.DequeueAsync(CancellationToken.None);
subject.Enqueue(10);
subject.Enqueue(11);
result.Result.Should().Be(10);
result2.Result.Should().Be(11);
}
示例2: Dequeue_should_return_an_uncompleted_task_when_no_items_exist
public void Dequeue_should_return_an_uncompleted_task_when_no_items_exist()
{
var subject = new AsyncQueue<int>();
var result = subject.DequeueAsync(CancellationToken.None);
result.IsCompleted.Should().BeFalse();
}
示例3: DequeueAsync_before_Enqueue
public void DequeueAsync_before_Enqueue()
{
var queue = new AsyncQueue<string>();
var task = queue.DequeueAsync().AssertNotCompleted();
queue.Enqueue("A");
task.AssertResult("A");
}
示例4: Dequeue_should_complete_when_an_item_is_added_to_the_queue
public void Dequeue_should_complete_when_an_item_is_added_to_the_queue()
{
var subject = new AsyncQueue<int>();
var result = subject.DequeueAsync(CancellationToken.None);
subject.Enqueue(10);
result.Result.Should().Be(10);
}
示例5: Enqueue
public void Enqueue()
{
var queue = new AsyncQueue<int>();
queue.Enqueue(42);
var task = queue.DequeueAsync();
Assert.True(task.IsCompleted);
Assert.Equal(42, task.Result);
}
示例6: DequeueThenEnqueue
public async Task DequeueThenEnqueue()
{
var queue = new AsyncQueue<int>();
var task = queue.DequeueAsync();
Assert.False(task.IsCompleted);
queue.Enqueue(13);
Assert.Equal(13, await task.ConfigureAwait(false));
}
示例7: AsyncQueueSkipsCancelledTasks
public async Task AsyncQueueSkipsCancelledTasks()
{
AsyncQueue<int> inputQueue = new AsyncQueue<int>();
// Queue up a couple of tasks to wait for input
CancellationTokenSource cancellationSource = new CancellationTokenSource();
Task<int> taskOne = inputQueue.DequeueAsync(cancellationSource.Token);
Task<int> taskTwo = inputQueue.DequeueAsync();
// Cancel the first task and then enqueue a number
cancellationSource.Cancel();
await inputQueue.EnqueueAsync(1);
// Did the second task get the number?
Assert.Equal(TaskStatus.Canceled, taskOne.Status);
Assert.Equal(TaskStatus.RanToCompletion, taskTwo.Status);
Assert.Equal(1, taskTwo.Result);
}
示例8: VerifyEvents
internal static void VerifyEvents(AsyncQueue<CompilationEvent> queue, params string[] expectedEvents)
{
var expected = new HashSet<string>();
foreach (var s in expectedEvents)
{
if (!expected.Add(s))
{
Console.WriteLine("Expected duplicate " + s);
}
}
var actual = ArrayBuilder<CompilationEvent>.GetInstance();
while (queue.Count > 0 || !queue.IsCompleted)
{
var te = queue.DequeueAsync();
Assert.True(te.IsCompleted);
actual.Add(te.Result);
}
bool unexpected = false;
foreach (var a in actual)
{
var eventString = a.ToString();
if (!expected.Remove(eventString))
{
if (!unexpected)
{
Console.WriteLine("UNEXPECTED EVENTS:");
unexpected = true;
}
Console.WriteLine(eventString);
}
}
if (expected.Count != 0)
{
Console.WriteLine("MISSING EVENTS:");
}
foreach (var e in expected)
{
Console.WriteLine(e);
}
if (unexpected || expected.Count != 0)
{
bool first = true;
Console.WriteLine("ACTUAL EVENTS:");
foreach (var e in actual)
{
if (!first)
{
Console.WriteLine(",");
}
first = false;
Console.Write("\"" + e.ToString() + "\"");
}
Console.WriteLine();
Assert.True(false);
}
}
示例9: CancelAllDequeue
public void CancelAllDequeue()
{
var queue = new AsyncQueue<string>();
var tasks = Enumerable.Range(0, 3).Select(_ => queue.DequeueAsync()).ToList();
queue.CancelAllDequeue().Dispose();
foreach (var task in tasks)
{
task.AssertCanceled();
}
}
示例10: CompleteAllDequeue
public void CompleteAllDequeue()
{
var queue = new AsyncQueue<string>();
var tasks = Enumerable.Range(0, 3).Select(_ => queue.DequeueAsync()).ToList();
queue.CompleteAllDequeue("X").Dispose();
foreach (var task in tasks)
{
task.AssertResult("X");
}
}
示例11: ConsumeItems
private async Task ConsumeItems(
AsyncQueue<int> inputQueue,
ConcurrentBag<int> outputItems,
CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
int consumedItem = await inputQueue.DequeueAsync(cancellationToken);
outputItems.Add(consumedItem);
}
}
示例12: DequeueAsync_canceled_after_completion
public void DequeueAsync_canceled_after_completion()
{
var queue = new AsyncQueue<string>();
queue.Enqueue("A");
using (var cts = new CancellationTokenSource())
{
var task = queue.DequeueAsync(cts.Token);
cts.Cancel();
task.AssertResult("A");
}
}
示例13: DequeueThenComplete
public async Task DequeueThenComplete()
{
var queue = new AsyncQueue<int>();
var task = queue.DequeueAsync();
Assert.False(task.IsCompleted);
queue.Complete();
var threw = false;
try
{
await task.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
threw = true;
}
Assert.True(threw);
}
示例14: DequeueManyThenEnqueueMany
public async Task DequeueManyThenEnqueueMany()
{
var queue = new AsyncQueue<int>();
var count = 4;
var list = new List<Task<int>>();
for (var i = 0; i < count; i++)
{
list.Add(queue.DequeueAsync());
}
for (var i = 0; i < count; i++)
{
var task = list[i];
Assert.False(task.IsCompleted);
queue.Enqueue(i);
Assert.Equal(i, await task.ConfigureAwait(false));
}
}
示例15: DequeueAsync_handled_in_order_of_caller
public void DequeueAsync_handled_in_order_of_caller()
{
var queue = new AsyncQueue<string>();
var values = new List<string> { "A", "B", "C" };
var tasks = values.Select(_ => queue.DequeueAsync()).ToList();
for (int i = 0; i < values.Count; i++)
{
tasks[i].AssertNotCompleted();
queue.Enqueue(values[i]);
tasks[i].AssertResult(values[i]);
}
}