mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 18:35:35 +00:00
Chnage LastApiInfo to GetLastApiInfo with cloned version
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user