/// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="token">浏览器取消请求时,服务端会将 HttpContext.RequestAborted 中的 Token 绑定到 Action 的 CancellationToken 参数。
        /// 我们只需在接口中增加参数 CancellationToken,并将其传入其他接口调用中,程序识别到令牌被取消就会自动放弃继续执行</param>
        /// <returns></returns>
        public async Task <WeatherForecastOutput> GetByIdAsync(int id, CancellationToken token)
        {
            var res = new WeatherForecastOutput();

            try
            {
                await _service.GetByIdAsync(id, token);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
            }
            return(res);
        }
Пример #2
0
        public Task<WeatherForecastOutput> GetByIdAsync(int id, CancellationToken token=default)
        {
			try
			{
				var res = new WeatherForecastOutput
				{
					Id = Guid.NewGuid().GetHashCode(),
					Date = DateTime.Now
				};

				return Task.FromResult(res);
			}
			catch (Exception e)
			{
				_logger.LogError(e, e.Message);
				throw e;
			}
		}