Skip to content

Commit

Permalink
Заменить finally на catch (#830)
Browse files Browse the repository at this point in the history
Из-за этого бага семафор освобождался всегда после выполнения и потом еще раз после вызова Dispose(). Это приводило к выбросу SemaphoreFullException.
  • Loading branch information
itsokto authored and inyutin-maxim committed Apr 16, 2019
1 parent ddee536 commit a08cff2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions VkNet/Utils/CountByIntervalAwaitableConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,28 @@ public class CountByIntervalAwaitableConstraint : IAwaitableConstraint

/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="CountByIntervalAwaitableConstraint" /> class
/// Initializes a new instance of the
/// <see cref="CountByIntervalAwaitableConstraint" /> class
/// with default values.
/// </summary>
public CountByIntervalAwaitableConstraint() : this(3, TimeSpan.FromSeconds(1))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CountByIntervalAwaitableConstraint"/> class,
/// Initializes a new instance of the
/// <see cref="CountByIntervalAwaitableConstraint" /> class,
/// specifying the maximum number of requests per time interval.
/// </summary>
/// <param name="number">
/// Maximum <paramref name="number"/> times per <paramref name="timeSpan"/>.
/// Maximum <paramref name="number" /> times per <paramref name="timeSpan" />.
/// </param>
/// <param name="timeSpan">
/// Time interval.
/// </param>
/// <exception cref="ArgumentException">
/// The <paramref name="number"/> and <paramref name="timeSpan"/> should be strictly positive.
/// The <paramref name="number" /> and <paramref name="timeSpan" /> should be
/// strictly positive.
/// </exception>
public CountByIntervalAwaitableConstraint(int number, TimeSpan timeSpan)
{
Expand Down Expand Up @@ -102,9 +105,9 @@ public async Task<IDisposable> WaitForReadiness(CancellationToken cancellationTo
await Task.Delay(timeToWait, cancellationToken).ConfigureAwait(false);
#endif
}
finally
catch
{
_semaphore.Release();
return new DisposableAction(OnEnded);
}

return new DisposableAction(OnEnded);
Expand Down

0 comments on commit a08cff2

Please sign in to comment.