示例#1
0
        public async Task <IEnumerable <OutputStory> > GetBestOrderedStories(bool disableCache)
        {
            var outputStories = new List <OutputStory>();

            using (var client = new HttpClient())
            {
                var bestStories = await _hackerNewsApi.GetBestStories();

                var stories = new List <Story>();

                Array.Sort(bestStories);

                var tasks = bestStories.Select(async storyId =>
                {
                    Story story = await GetStoryFromCache(storyId, disableCache);
                    stories.Add(story);
                }).ToList();

                Task.WaitAll(tasks.ToArray());

                outputStories = _mapper.Map <List <OutputStory> >(stories);
            }

            return(outputStories.OrderByDescending(s => s.score).Take(20));
        }