# pole

> Poll for async resources with an evented interface

Latest version **1.2.0** (published 2016-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install pole
pnpm add pole
yarn add pole
bun add pole
```

## 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.2.0 |
| Published | 2016-05-18 |
| First published | 2015-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | poll, async, events |

## Links

- npm: https://www.npmjs.com/package/pole
- Repository: https://github.com/bendrucker/pole
- Homepage: https://github.com/bendrucker/pole#readme
- Issues: https://github.com/bendrucker/pole/issues
- npm.io page: https://npm.io/package/pole

## Dependencies (10)

- [ap](https://npm.io/package/ap.md) ~0.2.0
- [geval](https://npm.io/package/geval.md) ~2.1.1
- [xtend](https://npm.io/package/xtend.md) ~4.0.0
- [observ](https://npm.io/package/observ.md) ~0.2.0
- [smallest](https://npm.io/package/smallest.md) ~1.0.0
- [value-pipe](https://npm.io/package/value-pipe.md) ~1.0.0
- [filter-pipe](https://npm.io/package/filter-pipe.md) ~1.0.1
- [observ-value](https://npm.io/package/observ-value.md) ~1.0.0
- [create-errback](https://npm.io/package/create-errback.md) ~1.0.0
- [observ-increment](https://npm.io/package/observ-increment.md) ~1.0.0

## 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.2.0 (latest) — 2016-05-18
- 1.1.1 — 2015-09-20
- 1.1.0 — 2015-09-20
- 1.0.0 — 2015-09-20

## README

# pole [![Build Status](https://travis-ci.org/bendrucker/pole.svg?branch=master)](https://travis-ci.org/bendrucker/pole)

> Poll for async resources with an evented interface


## Install

```
$ npm install --save pole
```


## Usage

```js
var poll = require('pole')

var user = pole(function (callback) {
  getUser(callback)  
})

user.onData(console.log)
user.onError(console.error)

user.cancel()
//=> stop polling and ignore any pending responses
```

## API

#### `poll([options], fn)` -> `object`

Returns a polling interface.

###### `onData(listener)` -> `function`

Calls `listener` when the polling request suceeded with the yielded value. Returns an unlisten function.

###### `onError(listener)` -> `function`

Calls `listener` when the polling request fails with the yielded error. Returns an unlisten function.

###### `cancel()` -> `undefined`

Stops the polling loop and ignores any pending responses.

##### options

Type: `object`

###### interval

Type: `number` / `function`  
Default: `0`

The interval in milliseconds between successful requests. This parameter can optionally be a function that will be called when data arrives and should return the interval as a number.

###### retryDelay

Type: `number`  
Default: `1000`

The interval in milliseconds between retries after failure. Retries are performed using exponential backoff. Given a `retryDelay` of `1000`, the first retry will be performed after 1 second, then 2, then 4, etc.

###### maxRetryDelay

Type: `number`  
Default: `30000`

The maximum interval in milliseconds between retries.

###### maxAttempts

Type: `number`  
Default: `5`

The number of attempts in total to make, including an initial attempt and `maxAttempts - 1` retries with backoff.

##### fn

Type: `function`  
Arguments: `callback<err, data>`

A function that will be called with a polling handler. `callback` is a Node errback.


## License

MIT © [Ben Drucker](http://bendrucker.me)

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