mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Cancel some delay tasks if they're not being used
This commit is contained in:
@@ -97,14 +97,23 @@ public class Blackjack
|
||||
|
||||
private async Task PromptUserMove(User usr)
|
||||
{
|
||||
var pause = Task.Delay(20000); //10 seconds to decide
|
||||
using var cts = new CancellationTokenSource();
|
||||
var pause = Task.Delay(20000, cts.Token); //10 seconds to decide
|
||||
CurrentUser = usr;
|
||||
currentUserMove = new();
|
||||
await PrintState();
|
||||
// either wait for the user to make an action and
|
||||
// if he doesn't - stand
|
||||
var finished = await Task.WhenAny(pause, currentUserMove.Task);
|
||||
if (finished == pause) await Stand(usr);
|
||||
if (finished == pause)
|
||||
{
|
||||
await Stand(usr);
|
||||
}
|
||||
else
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
|
||||
CurrentUser = null;
|
||||
currentUserMove = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user