mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add Cancellationtoken for downloadasync
Remove extra action in http for cancellation due to it will throw TaskCancelledExcpetion internally
This commit is contained in:
parent
2b085dbcee
commit
a6609d6b2c
1 changed files with 2 additions and 6 deletions
|
|
@ -76,11 +76,11 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
};
|
||||
}
|
||||
|
||||
public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath)
|
||||
public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var response = await client.GetAsync(url);
|
||||
using var response = await client.GetAsync(url, token);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
|
||||
|
|
@ -120,8 +120,6 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
{
|
||||
Log.Debug($"|Http.Get|Url <{url}>");
|
||||
using var response = await client.GetAsync(url, token);
|
||||
if (token.IsCancellationRequested)
|
||||
return string.Empty;
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
|
|
@ -143,8 +141,6 @@ namespace Flow.Launcher.Infrastructure.Http
|
|||
{
|
||||
Log.Debug($"|Http.Get|Url <{url}>");
|
||||
var response = await client.GetAsync(url, token);
|
||||
if (token.IsCancellationRequested)
|
||||
return Stream.Null;
|
||||
return await response.Content.ReadAsStreamAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue