Skip to content

A tool for making a promise which resolves if its given predicate resolves to truthy within a time interval.

License

Notifications You must be signed in to change notification settings

fennecbutt/promise-poll

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise-poll

Provides a function which resolves a promise which resolves within a given timeout if its predicate returns something truthy.

Installation

npm install promise-poll

Usage

var poll = require('promise-poll');

poll(rollOddDice, 1000).then(function(roll) {
  console.log('odd dice roll:', roll);
}, function(err) {
    console.error(err);
});

function rollOddDice() {
  var diceRoll = Math.floor(Math.random() * 6) + 1;
  return diceRoll % 2 ? diceRoll : false;
}

API

poll(predicate, timeout[, interval:ms]) : Promise

predicate

a function which returns a truthy values, whose first truthy value will be used to resolve the Promise

timeout

the number of milliseconds to wait before declaring the Promise rejected

interval

the number of milliseconds between attempts to test the predicate

About

A tool for making a promise which resolves if its given predicate resolves to truthy within a time interval.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%