# poll-func

> Poll any function until it returns the desired result.

Latest version **1.0.0** (published 2022-05-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install poll-func
pnpm add poll-func
yarn add poll-func
bun add poll-func
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-05-25 |
| First published | 2022-05-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | phillipdensmorechaffee@gmail.com |
| Maintainers | phillipchaffee |
| Keywords | async, poll, polling, function |

## Links

- npm: https://www.npmjs.com/package/poll-func
- Repository: https://github.com/PhillipChaffee/async-poll
- Issues: https://github.com/PhillipChaffee/async-poll/issues
- npm.io page: https://npm.io/package/poll-func

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-05-25

## README

# async-poll

## Table of contents

### Functions

- [asyncPoll](#asyncpoll)

### Type aliases

- [AsyncPollPromiseReject](#asyncpollpromisereject)
- [AsyncPollPromiseResolve](#asyncpollpromiseresolve)

## 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

| Name | Description |
| :------ | :------ |
| `T` | The data type that will be eventually returned |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `fn` | Function | The main async function to call repeatedly |
| `checkFn` | Function | The function that takes the result of the main function to determine if polling should be stopped |
| `pollInterval` | number | Milliseconds to wait before attempting to resolve the promise again. |
| `pollTimeout` | number | Max 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

| Name | Type |
| :------ | :------ |
| `reason?` | unknown |

##### Returns

void

#### Defined in

index.ts:2

___

### AsyncPollPromiseResolve

Ƭ **AsyncPollPromiseResolve**: Function

#### Type parameters

| Name |
| :------ |
| `T` |

#### Type declaration

▸ (`value`): void

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | T \| PromiseLike<T\> |

##### Returns

void

#### Defined in

index.ts:1

---
_Source: https://npm.io/package/poll-func · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
