Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #331 from dragonfruitnetwork/allow-token-refetch
Browse files Browse the repository at this point in the history
add refetch logic to tokens
  • Loading branch information
aspriddell authored Oct 22, 2022
2 parents f29d965 + 3a7ba00 commit e2a13a4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions DragonFruit.Six.Api/Dragon6Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,31 @@ static Dragon6Client()

protected internal async ValueTask<ClientTokenInjector> RequestToken()
{
if (_access?.Expired is false)
if (_access?.Expired == false)
{
return _access;
}

using (await _accessSync.LockAsync().ConfigureAwait(false))
{
// check again in case of a backlog
if (_access?.Expired is not false)
if (_access?.Expired == false)
{
return _access;
}

for (int i = 0; i < 2; i++)
{
var token = await GetToken(_access?.Token.SessionId).ConfigureAwait(false);
_access = new ClientTokenInjector(token);

if (!_access.Expired)
{
return _access;
}
}

return _access;
throw new InvalidTokenException(_access?.Token);
}
}
}
Expand Down

0 comments on commit e2a13a4

Please sign in to comment.