Method ConsumeUnitsAsync
ConsumeUnitsAsync(Int32, TimeSpan, Boolean, CancellationToken)
Consumes the specified number of units and blocks (sleeps)
asynchronously if required before an operation can proceed.
Declaration
public Task<TimeSpan> ConsumeUnitsAsync(int units, TimeSpan timeout, bool consumeOnTimeout, CancellationToken cancellationToken)
Parameters
Type |
Name |
Description |
Int32 |
units |
Number of units to consume. |
TimeSpan |
timeout |
Timeout. The resulting amount of time to sleep should not exceed
this timeout. If the sleep time exceeds this timeout, the
behavior should be according to consumeOnTimeout
parameter.
|
Boolean |
consumeOnTimeout |
Defines how rate limiter behaves when the timeout is reached. If
false , this method should throw
TimeoutException and the units should not be
consumed. If true , the units should be consumed even when
timeout is reached and this method should return successfully. In
either case, if the computed wait time exceeds timeout, this
method should still block (sleep) for the amount of time equal to
the timeout before either throwing an exception or returning
successfully (depending on the value of this parameter). The
driver uses the value true when calling
ConsumeUnitsAsync(Int32, TimeSpan, Boolean, CancellationToken) after an operation completes
successfully (see description in remarks), in which case the
exception should not be thrown and the result of the operation
should be returned to the application.
|
CancellationToken |
cancellationToken |
Cancellation token. |
Returns
Type |
Description |
Task<TimeSpan> |
Task returning TimeSpan of the amount of time
blocked (slept) by this method.
|
Implements
Exceptions
Type |
Condition |
TimeoutException |
If the specified timeout is reached and
consumeOnTimeout is false .
|