# easy-polling

> Easy-polling aims to achieve one simple and pure task:\ Check result of an asynchronous task until the result matched required criteria.\ This process is so called "polling" or "poll"!.

Latest version **1.1.3** (published 2020-11-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install easy-polling
pnpm add easy-polling
yarn add easy-polling
bun add easy-polling
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2020-11-10 |
| First published | 2020-11-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | paulatsydney |
| Maintainers | paulatsydney |
| Keywords | polling, poll, poller, async, interval, wait |

## Links

- npm: https://www.npmjs.com/package/easy-polling
- Repository: https://github.com/paulatsydney/easy-polling
- Homepage: https://github.com/paulatsydney/easy-polling#readme
- Issues: https://github.com/paulatsydney/easy-polling/issues
- npm.io page: https://npm.io/package/easy-polling

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.1.3 (latest) — 2020-11-10
- 1.1.2 — 2020-11-10
- 1.1.1 — 2020-11-10
- 1.1.0 — 2020-11-10
- 1.0.0 — 2020-11-10

## README

# easy-polling

Easy-polling aims to achieve one simple and pure task:\
Check result of an asynchronous task until the result matched required criteria.\
This process is so called "polling" or "poll"!.

## Get Started

Easy polling, easy to start~\
Hope you read below code snippet like a newspaper.:)

```js
npm i easy-polling
```

```js
const poll = require("easy-polling");

const fnAsyncTask = async () => {
    // Do some async task, like calling a webservice or API
    // Return a result which contains state to be checked
    // Using axios as an example
    return await axios.get("http://domain/api");
}

const fnValidate = (result) => {
    // Input parameter result is the return value of fnAsyncTask
    // Check state, below example check if status equal to done
    return result["status"] === "DONE";
};

// fnAsyncTask: Do some async task, it has a return value
// fnValidate: Check state of return value from above function, if true, return the value, otherwise keep polling
// Polling interval 1000ms
// Polling timeout 30000ms, which means if fnValidate returns false until timeout, polling return null
poll(fnAsyncTask, fnValidate, 1000, 30000).then(pollingResponse = > {
    console.log(pollingResponse);
});
```

## Github Repository

https://github.com/paulatsydney/easy-polling

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