示例#1
0
        public IActionResult GetDataSynchronous()
        {
            _logger.LogInformation("GetDataSynchronous");
            EarthquakeAPI            quakeSource = new EarthquakeAPI("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson");
            IEnumerable <Earthquake> quakes      = quakeSource.GetRecentEarthquakes().OrderByDescending(e => e.Magnitude);
            BitcoinPriceIndex        bpi         = CoinDeskAPI.GetBPI();

            return(Json(new { earthquakes = quakes, bitcoinPrices = bpi }));
        }
示例#2
0
        public async Task <IActionResult> GetDataAsynchronousParallel()
        {
            _logger.LogInformation("GetDataAsynchronousParallel");
            EarthquakeAPI quakeSource = new EarthquakeAPI("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson");
            // Start both asynchronous requests, each one returns a Task object immediately
            var task1 = quakeSource.GetRecentEarthquakesAsync();
            var task2 = CoinDeskAPI.GetBPIAsync();
            // await both of them
            await Task.WhenAll(task1, task2);

            // "Lift" results out of each task
            IEnumerable <Earthquake> quakes = task1.Result;
            BitcoinPriceIndex        bpi    = task2.Result;

            return(Json(new { earthquakes = quakes.OrderByDescending(e => e.Magnitude), bitcoinPrices = bpi }));
        }