Skip to main content

@terascope/utils / promises

promises

Index

Interfaces

InterfaceDescription
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

ParameterTypeDefault value
currentnumberundefined
factornumber2
maxnumber60000
minnumber500

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
ParameterType
reason?any
Returns

void

resolve()

resolve: (value?) => void

Parameters
ParameterType
value?unknown
Returns

void

Source

packages/utils/src/promises.ts:416


pDelay()

pDelay<T>(delay?, arg?): Promise<T>

promisified setTimeout

Type parameters

Type parameterValue
Tundefined

Parameters

ParameterType
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 parameterValue
Tundefined

Parameters

ParameterType
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

ParameterType
promisesPromise<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

ParameterType
promisesPromise<any> | Promise<any>[]
timeoutnumber
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 parameterValue
Tany

Parameters

ParameterType
fnPromiseFn<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

ParameterType
fnPromiseFn<any>
optionsPWhileOptions

Returns

Promise<void>

Source

packages/utils/src/promises.ts:243


waterfall()

waterfall(input, fns, addBreak): Promise<any>

Async waterfall function

Parameters

ParameterTypeDefault value
inputunknownundefined
fnsPromiseFn<any>[]undefined
addBreakbooleanfalse

Returns

Promise<any>

Source

packages/utils/src/promises.ts:349