Skip to content

Instantly share code, notes, and snippets.

@ChaosEngine
Created August 31, 2017 22:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChaosEngine/319c24c858d6b55cf8a7b8d293f0a828 to your computer and use it in GitHub Desktop.
Save ChaosEngine/319c24c858d6b55cf8a7b8d293f0a828 to your computer and use it in GitHub Desktop.
Cancellationtoken Edge test case
[HttpGet]
public async Task<IActionResult> Load(string sort, string order, string search, int limit, int offset, string extraParam)
{
CancellationToken token = HttpContext.RequestAborted;
try
{
var found = await _repo.SearchAsync(sort, order, search, offset, limit, token);
var result = new
{
total = found.Count,
rows = found.Itemz
};
var content = JsonConvert.SerializeObject(result, Formatting.None,
new JsonSerializerSettings() { MetadataPropertyHandling = MetadataPropertyHandling.Ignore });
return Content(content, "application/json");
}
catch (OperationCanceledException ex)
{
_logger.LogError(ex, $"Cancelled {nameof(Load)}::{nameof(_repo.SearchAsync)}({sort}, {order}, {search}, {offset}, {limit}, {token})");
return Ok();
}
catch (Exception ex)
{
_logger.LogError(ex, $"{nameof(Load)}::{nameof(_repo.SearchAsync)}({sort}, {order}, {search}, {offset}, {limit}, {token})");
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment