@terascope/utils / promises
promises
Index
Interfaces
Interface | Description |
---|---|
PRetryConfig | - |
Type Aliases
PWhileOptions
PWhileOptions:
object
Type declaration
enabledJitter?
optional
enabledJitter:boolean
enable jitter to stagger requests
error?
optional
error:string
error that can be expressed if the timer ends because the function does not return true
maxJitter?
optional
maxJitter:number
the maximum the jitter wait time will be (in milliseconds), defaults to 3x the minJitter setting, but less than timeoutMs
minJitter?
optional
minJitter:number
the minimum the jitter wait time will be (in milliseconds), defaults to 100ms
name?
optional
name:string
Defaults
to "Request"
timeoutMs?
optional
timeoutMs:number
Defaults
to -1 which is never
Source
packages/utils/src/promises.ts:217
Functions
getBackoffDelay()
getBackoffDelay(
current
,factor
,max
,min
):number
Get backoff delay that will safe to retry and is slightly staggered
Parameters
Parameter | Type | Default value |
---|---|---|
current | number | undefined |
factor | number | 2 |
max | number | 60000 |
min | number | 500 |
Returns
number
Source
packages/utils/src/promises.ts:316
pDefer()
pDefer():
object
An alternative to Bluebird.defer: http://bluebirdjs.com/docs/api/deferred-migration.html Considered bad practice in most cases, use the Promise constructor
Returns
object
promise
promise:
Promise
<any
>
reject()
reject: (
reason
?) =>void
Parameters
Parameter | Type |
---|---|
reason ? | any |
Returns
void
resolve()
resolve: (
value
?) =>void
Parameters
Parameter | Type |
---|---|
value ? | unknown |
Returns
void
Source
packages/utils/src/promises.ts:416
pDelay()
pDelay<
T
>(delay
?,arg
?):Promise
<T
>
promisified setTimeout
Type parameters
Type parameter | Value |
---|---|
T | undefined |
Parameters
Parameter | Type |
---|---|
delay ? | number |
arg ? | T |
Returns
Promise
<T
>
Source
packages/utils/src/promises.ts:13
pImmediate()
pImmediate<
T
>(arg
?):Promise
<T
>
promisified process.nextTick,setImmediate or setTimeout depending on your environment
Type parameters
Type parameter | Value |
---|---|
T | undefined |
Parameters
Parameter | Type |
---|---|
arg ? | T |
Returns
Promise
<T
>
Source
packages/utils/src/promises.ts:47
pRace()
pRace(
promises
,logError
?):Promise
<any
>
Run multiple promises at once, and resolve/reject when the first completes
Parameters
Parameter | Type |
---|---|
promises | Promise <any >[] |
logError ? | (err ) => void |
Returns
Promise
<any
>
Source
packages/utils/src/promises.ts:360
pRaceWithTimeout()
pRaceWithTimeout(
promises
,timeout
,logError
?):Promise
<any
>
Similar to pRace but with
Parameters
Parameter | Type |
---|---|
promises | Promise <any > | Promise <any >[] |
timeout | number |
logError ? | (err ) => void |
Returns
Promise
<any
>
Source
packages/utils/src/promises.ts:385
pRetry()
pRetry<
T
>(fn
,options
?):Promise
<T
>
A promise retry fn.
Type parameters
Type parameter | Value |
---|---|
T | any |
Parameters
Parameter | Type |
---|---|
fn | PromiseFn <T > |
options ? | Partial <PRetryConfig > |
Returns
Promise
<T
>
Source
packages/utils/src/promises.ts:125
pWhile()
pWhile(
fn
,options
):Promise
<void
>
Run a function until it returns true or throws an error
Parameters
Parameter | Type |
---|---|
fn | PromiseFn <any > |
options | PWhileOptions |
Returns
Promise
<void
>
Source
packages/utils/src/promises.ts:243
waterfall()
waterfall(
input
,fns
,addBreak
):Promise
<any
>
Async waterfall function
Parameters
Parameter | Type | Default value |
---|---|---|
input | unknown | undefined |
fns | PromiseFn <any >[] | undefined |
addBreak | boolean | false |
Returns
Promise
<any
>