예제 #1
0
        async Task <HashSet <string> > GetPatientSetAsync(IReadOnlyCollection <LeafQuery> queries, CancellationToken token)
        {
            var partials = new ConcurrentBag <PartialPatientCountContext>();
            var tasks    = new List <Task>();

            using (var throttler = new SemaphoreSlim(clinDbOpts.Cohort.MaxParallelThreads))
            {
                foreach (var q in queries)
                {
                    await throttler.WaitAsync();

                    tasks.Add(
                        Task.Run(async() =>
                    {
                        var result = await GetPartialContext(q, token);
                        throttler.Release();
                        partials.Add(result);
                    })
                        );
                }
                await Task.WhenAll(tasks);
            }
            token.ThrowIfCancellationRequested();

            return(patientCountAggregator.Aggregate(partials));
        }
예제 #2
0
        async Task <HashSet <string> > GetPatientSetAsync(IReadOnlyCollection <LeafQuery> queries, CancellationToken token)
        {
            var all      = queries.Select(q => GetPartialContext(q, token));
            var partials = await Task.WhenAll(all);

            token.ThrowIfCancellationRequested();

            return(patientCountAggregator.Aggregate(partials));
        }