poll-js

0.0.3 • Public • Published

poll-js Build Status npm version

Installation

Using npm: npm install poll-js

Using yarn: yarn add poll-js

Usage

import { pollWrapper } from 'poll-js';
 
const { future, cancel } = pollWrapper({
  request: fetch('github.com'),
  pollingPeriod: 1000 // ms,
  shouldStop: response => response.status === 200 
});
 
future
  .then(response => {...})
  .catch(error => {...})
 
// If by some reason you want to abort polling
cancel();  

API

.pollWrapper({request, pollingPeriod, shouldStop})

Returns Promise and cancel function. cancel allows manually terminate polling.

request - Function that returns Promise
pollingPeriod - Time in ms after request rejection and new attempt to perform it
shouldStop - Function which determines a condition for polling termination.

License

MIT © 2018 Mikhail Katrin mikhailkatrin@gmail.com

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    475
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    475
  • 0.0.2
    0
  • 0.0.1
    0
  • 0.0.0
    0

Package Sidebar

Install

npm i poll-js

Weekly Downloads

475

Version

0.0.3

License

MIT

Unpacked Size

78.4 kB

Total Files

8

Last publish

Collaborators

  • mikhail-katrin