本文整理汇总了C#中AsyncQueue类的典型用法代码示例。如果您正苦于以下问题:C# AsyncQueue类的具体用法?C# AsyncQueue怎么用?C# AsyncQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncQueue类属于命名空间,在下文中一共展示了AsyncQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DequeueAsync_before_Enqueue
public void DequeueAsync_before_Enqueue()
{
var queue = new AsyncQueue<string>();
var task = queue.DequeueAsync().AssertNotCompleted();
queue.Enqueue("A");
task.AssertResult("A");
}
示例2: TryEnqueueAfterComplete
public void TryEnqueueAfterComplete()
{
var queue = new AsyncQueue<int>();
Assert.True(queue.TryEnqueue(42));
queue.Complete();
Assert.False(queue.TryEnqueue(42));
}
示例3: MultiServerCluster
// constructors
public MultiServerCluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IEventSubscriber eventSubscriber)
: base(settings, serverFactory, eventSubscriber)
{
Ensure.IsGreaterThanZero(settings.EndPoints.Count, "settings.EndPoints.Count");
if (settings.ConnectionMode == ClusterConnectionMode.Standalone)
{
throw new ArgumentException("ClusterConnectionMode.StandAlone is not supported for a MultiServerCluster.");
}
if (settings.ConnectionMode == ClusterConnectionMode.Direct)
{
throw new ArgumentException("ClusterConnectionMode.Direct is not supported for a MultiServerCluster.");
}
_monitorServersCancellationTokenSource = new CancellationTokenSource();
_serverDescriptionChangedQueue = new AsyncQueue<ServerDescriptionChangedEventArgs>();
_servers = new List<IClusterableServer>();
_state = new InterlockedInt32(State.Initial);
_replicaSetName = settings.ReplicaSetName;
eventSubscriber.TryGetEventHandler(out _closingEventHandler);
eventSubscriber.TryGetEventHandler(out _closedEventHandler);
eventSubscriber.TryGetEventHandler(out _openingEventHandler);
eventSubscriber.TryGetEventHandler(out _openedEventHandler);
eventSubscriber.TryGetEventHandler(out _addingServerEventHandler);
eventSubscriber.TryGetEventHandler(out _addedServerEventHandler);
eventSubscriber.TryGetEventHandler(out _removingServerEventHandler);
eventSubscriber.TryGetEventHandler(out _removedServerEventHandler);
}
示例4: 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();
}
示例5: AnalyzerDriver
/// <summary>
/// Create an analyzer driver.
/// </summary>
/// <param name="analyzers">The set of analyzers to include in the analysis</param>
/// <param name="options">Options that are passed to analyzers</param>
/// <param name="cancellationToken">a cancellation token that can be used to abort analysis</param>
/// <param name="continueOnAnalyzerException">Delegate which is invoked when an analyzer throws an exception.
/// If a non-null delegate is provided and it returns true, then the exception is handled and converted into a diagnostic and driver continues with other analyzers.
/// Otherwise if it returns false, then the exception is not handled by the driver.
/// If null, then the driver always handles the exception.
/// </param>
protected AnalyzerDriver(ImmutableArray<IDiagnosticAnalyzer> analyzers, AnalyzerOptions options, CancellationToken cancellationToken, Func<Exception, IDiagnosticAnalyzer, bool> continueOnAnalyzerException = null)
{
this.CompilationEventQueue = new AsyncQueue<CompilationEvent>();
this.DiagnosticQueue = new AsyncQueue<Diagnostic>();
this.addDiagnostic = GetDiagnosticSinkWithSuppression();
this.analyzerOptions = options;
Func<Exception, IDiagnosticAnalyzer, bool> defaultExceptionHandler = (exception, analyzer) => true;
this.continueOnAnalyzerException = continueOnAnalyzerException ?? defaultExceptionHandler;
// start the first task to drain the event queue. The first compilation event is to be handled before
// any other ones, so we cannot have more than one event processing task until the first event has been handled.
initialWorker = Task.Run(async () =>
{
try
{
await InitialWorkerAsync(analyzers, continueOnAnalyzerException, cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// If creation is cancelled we had better not use the driver any longer
this.Dispose();
}
});
}
示例6: 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);
}
示例7: 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);
}
示例8: 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));
}
示例9: AlarmAdapter
/// <summary>
/// Creates a new instance of the <see cref="AlarmAdapter"/>.
/// </summary>
public AlarmAdapter()
{
m_measurementQueue = new AsyncQueue<IEnumerable<IMeasurement>>()
{
ProcessItemFunction = ProcessMeasurements
};
m_measurementQueue.ProcessException += m_measurementQueue_ProcessException;
}
示例10: TryEnqueueAfterPromisingNotTo
public void TryEnqueueAfterPromisingNotTo()
{
var queue = new AsyncQueue<int>();
Assert.True(queue.TryEnqueue(42));
queue.PromiseNotToEnqueue();
Assert.Throws(typeof(InvalidOperationException), () => {
queue.TryEnqueue(42);
});
}
示例11: 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);
}
}
示例12: 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();
}
}
示例13: 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");
}
}
示例14: Count_nonempty
public void Count_nonempty()
{
var queue = new AsyncQueue<string>();
queue.Enqueue("A");
queue.Enqueue("B");
queue.Enqueue("C");
queue.Enqueue("D");
Assert.IsTrue(queue.TryDequeue());
Assert.AreEqual(3, queue.Count);
}
示例15: 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");
}
}