Skip to content

Commit d74a8a9

Browse files
committed
Add missing 'break' to BotFramework and ConfigureAwait(false) to ScriptedBot async calls.
1 parent 43f80fa commit d74a8a9

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

EOBot/BotFramework.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ public async Task InitializeAsync(IBotFactory botFactory, int delayBetweenInitsM
6464
{
6565
var bot = botFactory.CreateBot(i);
6666
bot.WorkCompleted += () => _doneSignal.Release();
67-
await bot.InitializeAsync(_host, _port);
67+
await bot.InitializeAsync(_host, _port).ConfigureAwait(false);
6868
_botsList.Add(bot);
6969

7070
ConsoleHelper.WriteMessage(ConsoleHelper.Type.None, $"Bot {i} initialized.");
71-
await Task.Delay(delayBetweenInitsMS); // minimum for this is 1sec server-side
71+
await Task.Delay(delayBetweenInitsMS).ConfigureAwait(false); // minimum for this is 1sec server-side
72+
73+
break;
7274
}
7375
catch (Exception ex)
7476
{
@@ -83,7 +85,7 @@ public async Task InitializeAsync(IBotFactory botFactory, int delayBetweenInitsM
8385
{
8486
var retryDelayTime = TimeSpan.FromMilliseconds(delayBetweenInitsMS + (1000 * attempt * attempt));
8587
ConsoleHelper.WriteMessage(ConsoleHelper.Type.Warning, $"Bot {i} failed to initialize. Retrying in {retryDelayTime.TotalMilliseconds}ms...", ConsoleColor.DarkYellow);
86-
await Task.Delay(retryDelayTime);
88+
await Task.Delay(retryDelayTime).ConfigureAwait(false);
8789
}
8890
}
8991
}
@@ -123,7 +125,7 @@ public async Task RunAsync()
123125
var continuation = Task.WhenAll(botTasks);
124126
try
125127
{
126-
await continuation;
128+
await continuation.ConfigureAwait(false);
127129
}
128130
catch { }
129131

EOBot/Interpreter/BuiltInIdentifierConfigurator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ private async Task ConnectAsync(string host, int port)
116116
configRepo.VersionBuild = ((IntVariable)_state.SymbolTable[PredefinedIdentifiers.VERSION].Identifiable).Value;
117117

118118
var connectionActions = c.Resolve<INetworkConnectionActions>();
119-
var connectResult = await connectionActions.ConnectToServer();
119+
var connectResult = await connectionActions.ConnectToServer().ConfigureAwait(false);
120120
if (connectResult != ConnectResult.Success)
121121
throw new ArgumentException($"Bot {_botIndex}: Unable to connect to server! Host={host} Port={port}");
122122

123123
var backgroundReceiveActions = c.Resolve<IBackgroundReceiveActions>();
124124
backgroundReceiveActions.RunBackgroundReceiveLoop();
125125

126-
var handshakeResult = await connectionActions.BeginHandshake(_random.Next(Constants.MaxChallenge));
126+
var handshakeResult = await connectionActions.BeginHandshake(_random.Next(Constants.MaxChallenge)).ConfigureAwait(false);
127127

128128
if (handshakeResult.ReplyCode != InitReply.Ok)
129129
throw new InvalidOperationException($"Bot {_botIndex}: Invalid response from server or connection failed! Must receive an OK reply.");
@@ -149,38 +149,38 @@ private void Disconnect()
149149

150150
private async Task<int> CreateAccountAsync(string user, string pass)
151151
{
152-
return (int)await _botHelper.CreateAccountAsync(user, pass);
152+
return (int)await _botHelper.CreateAccountAsync(user, pass).ConfigureAwait(false);
153153
}
154154

155155
private async Task<int> LoginAsync(string user, string pass)
156156
{
157-
return (int)await _botHelper.LoginToAccountAsync(user, pass);
157+
return (int)await _botHelper.LoginToAccountAsync(user, pass).ConfigureAwait(false);
158158
}
159159

160160
private async Task<int> CreateAndLoginAsync(string user, string pass)
161161
{
162-
var accountReply = (AccountReply)await CreateAccountAsync(user, pass);
162+
var accountReply = (AccountReply)await CreateAccountAsync(user, pass).ConfigureAwait(false);
163163
if (accountReply == AccountReply.Created || accountReply == AccountReply.Exists)
164164
{
165-
return await LoginAsync(user, pass);
165+
return await LoginAsync(user, pass).ConfigureAwait(false);
166166
}
167167

168168
return (int)LoginReply.WrongUser;
169169
}
170170

171171
private async Task<int> ChangePasswordAsync(string user, string oldPass, string newPass)
172172
{
173-
return (int)await _botHelper.ChangePasswordAsync(user, oldPass, newPass);
173+
return (int)await _botHelper.ChangePasswordAsync(user, oldPass, newPass).ConfigureAwait(false);
174174
}
175175

176176
private async Task<int> CreateCharacterAsync(string charName)
177177
{
178-
return (int)await _botHelper.CreateCharacterAsync(charName);
178+
return (int)await _botHelper.CreateCharacterAsync(charName).ConfigureAwait(false);
179179
}
180180

181181
private async Task<int> DeleteCharacterAsync(string charName, bool force)
182182
{
183-
return (int)await _botHelper.DeleteCharacterAsync(charName, force);
183+
return (int)await _botHelper.DeleteCharacterAsync(charName, force).ConfigureAwait(false);
184184
}
185185

186186
private Task LoginToCharacterAsync(string charName)

EOBot/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ static async Task<int> Main(string[] args)
217217
{
218218
using (f = new BotFramework(parsedArgs))
219219
{
220-
await f.InitializeAsync(botFactory, parsedArgs.InitDelay);
221-
await f.RunAsync();
220+
await f.InitializeAsync(botFactory, parsedArgs.InitDelay).ConfigureAwait(false);
221+
await f.RunAsync().ConfigureAwait(false);
222222
}
223223

224224
Console.WriteLine();

EOBot/ScriptedBot.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override async Task InitializeAsync(string host, int port)
3232
throw new InvalidOperationException("Something went wrong getting the connect function out of the symbol table");
3333

3434
// call connect function that uses user-defined $version variable instead of base logic that has it hard-coded
35-
await connectFunction.CallAsync(new StringVariable(_parsedArgs.Host), new IntVariable(_parsedArgs.Port));
35+
await connectFunction.CallAsync(new StringVariable(_parsedArgs.Host), new IntVariable(_parsedArgs.Port)).ConfigureAwait(false);
3636

3737
WorkCompleted += () =>
3838
{
@@ -51,7 +51,7 @@ protected override async Task DoWorkAsync(CancellationToken ct)
5151
if (_programState == null)
5252
throw new InvalidOperationException("Scripted bot must be initialized before it is run");
5353

54-
await _interpreter.Run(_programState);
54+
await _interpreter.Run(_programState).ConfigureAwait(false);
5555
}
5656
}
5757
}

0 commit comments

Comments
 (0)