[英]Is it fine to await for one Task but not for other?
我有以下服務方法,
public async Task<IList<ProductsImage>> InsertAsync(BaseProduct product, Dictionary<string, Stream> images)
{
try
{
if (images.Count > 0)
{
await _imageService.SaveAllAsync(images);
}
return await _repository.InsertAsync(product);
}
catch // Delete the files if there is an error from db
{
if (images.Count > 0)
{
var paths = images.Select(i => i.Key).ToList();
_imageService.DeleteAllAsync(paths);
}
throw;
}
}
問題是我不想在_imageService.DeleteAllAsync
等待,因為它需要一些時間才能完成,所以我可以在不等待的情況下傳輸執行。 在_imageService.DeleteAllAsync
是否存在不使用await的_imageService.DeleteAllAsync
正確的方法是將此消息發送到消息隊列,以便可以由外部進程異步處理(無需等待)。 這樣,它還可以保證DeleteAllAsync在失敗時被調用或重試。
這是我在這個主題上寫的文章的無恥插件 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.