Skip to content

Commit

Permalink
Minor async improvements (#49)
Browse files Browse the repository at this point in the history
* Removed unnecessary awaits in MandrillExportsApi

* Using ConfigureAwait(false) for MandrillRequest and MandrillUsersApi
  • Loading branch information
danielmarbach authored and feinoujc committed May 3, 2016
1 parent 713cf7b commit 052eba9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
20 changes: 10 additions & 10 deletions src/Mandrill.net/MandrillExportsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,48 @@ public MandrillExportsApi(MandrillApi mandrillApi)
}
public MandrillApi MandrillApi { get; set; }

public async Task<IList<MandrillExportInfo>> ListAsync()
public Task<IList<MandrillExportInfo>> ListAsync()
{
return await MandrillApi.PostAsync<MandrillExportRequest, IList<MandrillExportInfo>>("exports/list.json",
return MandrillApi.PostAsync<MandrillExportRequest, IList<MandrillExportInfo>>("exports/list.json",
new MandrillExportRequest());
}

public async Task<MandrillExportInfo> InfoAsync(string id)
public Task<MandrillExportInfo> InfoAsync(string id)
{
return await MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/info.json",
return MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/info.json",
new MandrillExportRequest
{
Id = id
});
}

public async Task<MandrillExportInfo> RejectsAsync(string notifyEmail)
public Task<MandrillExportInfo> RejectsAsync(string notifyEmail)
{
return await MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/rejects.json",
return MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/rejects.json",
new MandrillExportRequest
{
NotifyEmail = notifyEmail
});
}

public async Task<MandrillExportInfo> WhitelistAsync(string notifyEmail)
public Task<MandrillExportInfo> WhitelistAsync(string notifyEmail)
{
return await MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/whitelist.json",
return MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/whitelist.json",
new MandrillExportRequest
{
NotifyEmail = notifyEmail
});
}

public async Task<MandrillExportInfo> ActivityAsync(string notifyEmail,
public Task<MandrillExportInfo> ActivityAsync(string notifyEmail,
DateTime? dateFrom = null,
DateTime? dateTo = null,
IList<string> tags = null,
IList<string> senders = null,
IList<string> states = null,
IList<string> apiKeys = null)
{
return await MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/activity",
return MandrillApi.PostAsync<MandrillExportRequest, MandrillExportInfo>("exports/activity",
new MandrillExportRequest
{
NotifyEmail = notifyEmail,
Expand Down
12 changes: 7 additions & 5 deletions src/Mandrill.net/MandrillRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ public override async Task<TResponse> PostAsync<TRequest, TResponse>(string requ
MandrillSerializer<TRequest>.Serialize(jsonWriter, value);
jsonWriter.Flush();
inputStream.Seek(0, SeekOrigin.Begin);
using (var requestStream = await request.GetRequestStreamAsync())
using (var requestStream = await request.GetRequestStreamAsync().ConfigureAwait(false))
{
await inputStream.CopyToAsync(requestStream);
await inputStream.CopyToAsync(requestStream).ConfigureAwait(false);
}
}

try
{
using (var response = (HttpWebResponse) await request.GetResponseAsync())
using (var response = (HttpWebResponse) await request.GetResponseAsync().ConfigureAwait(false))
using (var responseStream = response.GetResponseStream())
using (var jsonReader = new JsonTextReader(new StreamReader(responseStream)))
using(var responseReader = new StreamReader(responseStream))
using (var jsonReader = new JsonTextReader(responseReader))
{
return MandrillSerializer<TResponse>.Deserialize(jsonReader);
}
Expand All @@ -113,7 +114,8 @@ private static MandrillException ExtractMandrillErrorResponse(string requestUri,
{
using (var response = webResponse)
using (var responseStream = response.GetResponseStream())
using (var jsonReader = new JsonTextReader(new StreamReader(responseStream)))
using (var responseReader = new StreamReader(responseStream))
using (var jsonReader = new JsonTextReader(responseReader))
{
error = MandrillSerializer<MandrillErrorResponse>.Deserialize(jsonReader);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mandrill.net/MandrillUsersApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public MandrillUsersApi(MandrillApi mandrillApi)
public async Task<string> PingAsync()
{
return (await MandrillApi.PostAsync<MandrillUsersRequest, JObject>("users/ping2.json",
new MandrillUsersRequest()))["PING"].Value<string>();
new MandrillUsersRequest()).ConfigureAwait(false))["PING"].Value<string>();
}

public Task<IList<MandrillSenderDemographics>> SendersAsync()
Expand Down

0 comments on commit 052eba9

Please sign in to comment.