1.2.0 • Published 8 years ago

pole v1.2.0

Weekly downloads
11
License
MIT
Repository
github
Last release
8 years ago

pole Build Status

Poll for async resources with an evented interface

Install

$ npm install --save pole

Usage

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

1.2.0

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.1.0

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago