Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsys/gallup
:bar_chart: Poll any resource using ES6 Promises and streams
https://github.com/dsys/gallup
Last synced: about 1 month ago
JSON representation
:bar_chart: Poll any resource using ES6 Promises and streams
- Host: GitHub
- URL: https://github.com/dsys/gallup
- Owner: dsys
- License: bsd-3-clause
- Created: 2015-10-29T21:34:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-31T02:16:33.000Z (about 9 years ago)
- Last Synced: 2024-08-09T10:26:43.577Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 344 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![TravisCI shield](https://img.shields.io/travis/pavlovml/gallup.svg)](https://travis-ci.org/pavlovml/gallup) [![npm shield](https://img.shields.io/npm/v/gallup.svg)](https://www.npmjs.com/package/gallup) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
Poll any resource using ES6 Promises and streams.
## Installation
$ npm install gallup --save
## Usage
```javascript
import Gallup from 'gallup'// You construct a poller by providing a poll callback as the first argument
// and an optional options object as the second. The poll function may return a
// normal value or an ES6 Promise to be evaluated.var poller = new Gallup(() => {
return Promise.resolve({ stub: 'data' })
}, 5000) // poll every 5 seconds (default: 1 second)// Pollers are stopped by default. Starting them begins polling immediately.
poller.start()// Pollers are instances of EventEmitter. When promises resolve, their values
// are emitted via 'data' events. Errors are emitted via 'error' events. If the
// previous poll is taking a long time to resolve, another poll will not be
// initiated until the previous one completes.poller.on('data', data => {
console.log(data)
})poller.on('error', err => {
console.error(err)
})// You can also stop and restart polling.
poller.stop()
poller.start()
```## Development
Gallup uses [JavaScript Standard Style](https://github.com/feross/standard), [Babel](https://babeljs.io/) for ES6+ support, and [Jest](http://facebook.github.io/jest/) for testing.
$ git clone [email protected]:pavlovml/gallup.git
$ npm testTo run the tests on file changes:
$ npm test -- --watch
## License
[BSD 3-Clause](https://github.com/pavlovml/gallup/blob/master/LICENSE)