AsyncDolls.Comonaden.PushMessages.StopAsync C# (CSharp) Method

StopAsync() public method

public StopAsync ( ) : Task
return Task
        public async Task StopAsync()
        {
            tokenSource.Cancel();

            await pumpTask.IgnoreCancellation().ConfigureAwait(false);
            await Task.WhenAll(runningTasks.Values).ConfigureAwait(false);

            runningTasks.Clear();
            semaphore.Dispose();
            tokenSource.Dispose();
        }
    }

Usage Example

Ejemplo n.º 1
0
        public async Task Do()
        {
            var messages = new ConcurrentQueue <TransportMessage>();

            messages.Enqueue(new TransportMessage());
            messages.Enqueue(new TransportMessage());
            messages.Enqueue(new TransportMessage());

            var countdown = new AsyncCountdownEvent(3);

            var pipelineFactory = new ChainFactory();

            pipelineFactory.Register(() => new LogStep(countdown));
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new DelayInUsing());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new PassThrough());
            pipelineFactory.Register(() => new PassThrough());
            pipelineFactory.Register(() => new PassThrough());
            pipelineFactory.Register(() => new DelayInUsing());
            pipelineFactory.Register(() => new DelayBefore());
            pipelineFactory.Register(() => new DelayAfter());
            pipelineFactory.Register(() => new PassThrough());
            pipelineFactory.Register(() => new PassThrough());
            pipelineFactory.Register(() => new PassThrough());
            pipelineFactory.Register(() => new ThrowException());

            var strategy = new PushMessages(messages, maxConcurrency: 1);

            await strategy.StartAsync(tm => Connector(pipelineFactory, tm));

            await Task.Delay(2000);

            await strategy.StopAsync();
        }
All Usage Examples Of AsyncDolls.Comonaden.PushMessages::StopAsync