Exemplo n.º 1
0
        private static async Task RunProducer(IProducer <TP> parallelProducer,
                                              IProducerBuffer <TP> feed, CancellationToken token,
                                              CancellationTokenSource tokenSrc)
        {
            try
            {
#if NETFRAMEWORK || NETSTANDARD2_0
                using (parallelProducer)
#else
                await using (parallelProducer.ConfigureAwait(false))
#endif
                {
                    await parallelProducer.InitAsync().StartIfNeeded().ConfigureAwait(false);

                    token.ThrowIfCancellationRequested();
                    await parallelProducer.ProduceAsync(feed, token).StartIfNeeded().ConfigureAwait(false);
                }
            }
            catch
            {
                if (!token.IsCancellationRequested)
                {
                    tokenSrc.Cancel();
                }
                throw;
            }
        }
Exemplo n.º 2
0
 public async Task ProduceAsync(IProducerBuffer <T> feedToPopulate, CancellationToken cancellationToken)
 {
     await _producerFunc(feedToPopulate, cancellationToken).ConfigureAwait(false);
 }