Constructor
new Backoff(parameters, opt_autoResetopt, opt_isCanceledopt, nullable)
Backoff represents delay and backoff state. This is used by NetworkingEngine
for individual requests and by StreamingEngine to retry streaming failures.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parameters |
shakaExtern.RetryParameters | ||
opt_autoReset |
boolean |
<optional> |
If true, start at a "first retry" state and and auto-reset that state when we reach maxAttempts. |
opt_isCanceled |
?function()= |
<optional> <nullable> |
If provided, the backoff will end the current attempt early when this callback returns true. |
- Source:
Members
-
(private) autoReset_ :boolean
-
Type:
- boolean
- Source:
-
(private, constant) backoffFactor_ :number
-
Type:
- number
- Source:
-
(private, constant) baseDelay_ :number
-
Type:
- number
- Source:
-
(private, constant) fuzzFactor_ :number
-
Type:
- number
- Source:
-
(private, nullable) isCanceled_ :?function()
-
Type:
- ?function()
- Source:
-
(private, constant) maxAttempts_ :number
-
Type:
- number
- Source:
-
(private) nextUnfuzzedDelay_ :number
-
Type:
- number
- Source:
-
(private) numAttempts_ :number
-
Type:
- number
- Source:
Methods
-
(static) defaultRetryParameters() → {shakaExtern.RetryParameters}
-
Gets a copy of the default retry parameters.
- Source:
Returns:
-
(private, static) fuzz_(value, fuzzFactor) → {number}
-
Fuzz the input value by +/- fuzzFactor. For example, a fuzzFactor of 0.5 will create a random value that is between 50% and 150% of the input value.
Parameters:
Name Type Description value
number fuzzFactor
number - Source:
Returns:
The fuzzed value- Type
- number
-
(private, static) setTimeout_(fn, timeoutMs) → {number}
-
This is here only for testability. Mocking global setTimeout can lead to unintended interactions with other tests. So instead, we mock this.
Parameters:
Name Type Description fn
Function The callback to invoke when the timeout expires. timeoutMs
number The timeout in milliseconds. - Source:
Returns:
The timeout ID.- Type
- number
-
attempt() → (non-null) {Promise}
-
- Source:
Returns:
Resolves when the caller may make an attempt, possibly after a delay. Rejects if no more attempts are allowed.- Type
- Promise
-
(private) cancelableTimeout_(fn, timeoutMs)
-
Makes a timeout that cancels with isCanceled_ if this has an isCanceled_.
Parameters:
Name Type Description fn
Function The callback to invoke when the timeout expires. timeoutMs
number The timeout in milliseconds. - Source:
-
(private) reset_()
-
Reset state in autoReset mode.
- Source: