Chnage LastApiInfo to GetLastApiInfo with cloned version

This commit is contained in:
Mark Taylor
2015-08-16 21:27:26 +01:00
parent 5bd1f1d6c5
commit b2c7e1c2a7
13 changed files with 224 additions and 33 deletions
+9 -18
View File
@@ -140,25 +140,15 @@ namespace Octokit
/// Gets the latest API Info - this will be null if no API calls have been made
/// </summary>
/// <returns><seealso cref="ApiInfo"/> representing the information returned as part of an Api call</returns>
public ApiInfo LastApiInfo
{
get
{
lock (LastApiInfoLocker)
{
return _lastApiInfo;
}
}
private set
{
lock (LastApiInfoLocker)
{
_lastApiInfo = value;
}
}
public ApiInfo GetLastApiInfo()
{
// We've choosen to not wrap the _lastApiInfo in a lock. Originally the code was returning a reference - so there was a danger of
// on thread writing to the object while another was reading. Now we are cloning the ApiInfo on request - thus removing the need (or overhead)
// of putting locks in place.
// See https://github.com/octokit/octokit.net/pull/855#discussion_r36774884
return _lastApiInfo == null ? null : _lastApiInfo.Clone();
}
private ApiInfo _lastApiInfo;
private readonly object LastApiInfoLocker = new object();
public Task<IApiResponse<T>> Get<T>(Uri uri, IDictionary<string, string> parameters, string accepts)
{
@@ -550,7 +540,8 @@ namespace Octokit
var response = await _httpClient.Send(request, cancellationToken).ConfigureAwait(false);
if (response != null)
{
LastApiInfo = response.ApiInfo;
// Use the clone method to avoid keeping hold of the original (just in case it effect the lifetime of the whole response
_lastApiInfo = response.ApiInfo.Clone();
}
HandleErrors(response);
return response;