Make sure SSHClient Disconnect does not hang if a cancellationToken is passed

This commit is contained in:
nicolas.dorier
2019-10-21 18:43:53 +09:00
parent 4d68b12080
commit 12264d8e74
2 changed files with 6 additions and 3 deletions

View File

@@ -102,7 +102,7 @@ namespace BTCPayServer
};
}
public static Task DisconnectAsync(this SshClient sshClient)
public static async Task DisconnectAsync(this SshClient sshClient, CancellationToken cancellationToken = default)
{
if (sshClient == null)
throw new ArgumentNullException(nameof(sshClient));
@@ -121,7 +121,10 @@ namespace BTCPayServer
}
})
{ IsBackground = true }.Start();
return tcs.Task;
using (cancellationToken.Register(() => tcs.TrySetCanceled()))
{
await tcs.Task;
}
}
}
}