Skip to content

Commit

Permalink
Fix awaiting null tasks, closes #128
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Mar 6, 2016
1 parent eddcc28 commit b9064bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions ArchiSteamFarm/ArchiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ limitations under the License.

using SteamKit2;
using SteamKit2.Internal;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;

namespace ArchiSteamFarm {
internal sealed class ArchiHandler : ClientMsgHandler {
Expand Down Expand Up @@ -216,7 +218,7 @@ internal void PlayGames(ICollection<uint> gameIDs) {
Client.Send(request);
}

internal AsyncJob<PurchaseResponseCallback> RedeemKey(string key) {
internal async Task<PurchaseResponseCallback> RedeemKey(string key) {
if (string.IsNullOrEmpty(key) || !Client.IsConnected) {
return null;
}
Expand All @@ -228,7 +230,12 @@ internal AsyncJob<PurchaseResponseCallback> RedeemKey(string key) {
request.Body.key = key;

Client.Send(request);
return new AsyncJob<PurchaseResponseCallback>(Client, request.SourceJobID);
try {
return await new AsyncJob<PurchaseResponseCallback>(Client, request.SourceJobID);
} catch (Exception e) {
Logging.LogGenericException(e);
return null;
}
}

/*
Expand Down
4 changes: 2 additions & 2 deletions ArchiSteamFarm/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ private async Task<string> ResponseRedeem(string message, bool validate) {

ArchiHandler.PurchaseResponseCallback result;
try {
result = await currentBot.ArchiHandler.RedeemKey(key);
result = await currentBot.ArchiHandler.RedeemKey(key).ConfigureAwait(false);
} catch (Exception e) {
Logging.LogGenericException(e, currentBot.BotName);
break;
Expand Down Expand Up @@ -575,7 +575,7 @@ private async Task<string> ResponseRedeem(string message, bool validate) {

ArchiHandler.PurchaseResponseCallback otherResult;
try {
otherResult = await bot.ArchiHandler.RedeemKey(key);
otherResult = await bot.ArchiHandler.RedeemKey(key).ConfigureAwait(false);
} catch (Exception e) {
Logging.LogGenericException(e, bot.BotName);
break; // We're done with this key
Expand Down

0 comments on commit b9064bb

Please sign in to comment.