1.0.0 • Published 2 years ago

poll-func v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

async-poll

Table of contents

Functions

Type aliases

Functions

asyncPoll

asyncPoll<T>(fn, checkFn, pollInterval?, pollTimeout?): Promise<T>

An async function that takes an async function as argument and runs it until the result satisfies a check function.

Inspired by the following gist: https://gist.github.com/douglascayers/346e061fb7c1f38da00ee98c214464ae

Type parameters

NameDescription
TThe data type that will be eventually returned

Parameters

NameTypeDescription
fnFunctionThe main async function to call repeatedly
checkFnFunctionThe function that takes the result of the main function to determine if polling should be stopped
pollIntervalnumberMilliseconds to wait before attempting to resolve the promise again.
pollTimeoutnumberMax time to keep polling to receive a successful resolved response.

Returns

Promise<T>

A promise that will return either the desired result, an error, or timeout

Defined in

index.ts:20

Type aliases

AsyncPollPromiseReject

Ƭ AsyncPollPromiseReject: Function

Type declaration

▸ (reason?): void

Parameters
NameType
reason?unknown
Returns

void

Defined in

index.ts:2


AsyncPollPromiseResolve

Ƭ AsyncPollPromiseResolve: Function

Type parameters

Name
T

Type declaration

▸ (value): void

Parameters
NameType
valueT | PromiseLike<T>
Returns

void

Defined in

index.ts:1