npm.io
1.1.4 • Published 9 years ago

pollr

Licence
ISC
Version
1.1.4
Deps
0
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

pollr

A JavaScript/AJAX polling engine.

Usage

import Pollr from 'pollr';

var pollr = new Pollr({
  url: '/test',
  retries: 10,
  interval: 3000,
  responseType: 'json'
});

pollr.on('data', function(data) {
  if (data.foo === 'bar') {
    // Do something awesome
    pollr.stop(); 
  }
});

pollr.on('error', function(error) {
  console.error(error); // Called when response.statusCode != 200
});

pollr.start(); // Polls the server 11 times, unless stopped

Other Examples

Continuous polling
pollr.retries = null; 
pollr.start(); // Will poll until stopped
Post data
pollr.method = 'post';
pollr.data = { message: 'Is anybody home...?' };

Contact

AJ Bond