node-waiter

1.0.1 • Public • Published

node-waiter

helper functions which make your code wait

Installation

npm i node-waiter

Usage

  • wait(time) - Returns a promise which resolves after a given time
const waiter = require('node-waiter');

waiter
  .wait(5000)
  .then(() => console.log('I\'ve been waiting for 5 seconds!'));
  • waitUntil(doWhat, untilWhen, max) - Returns a promise which resolves after a given condition is met
const waiter = require('node-waiter');

/**
 * Example of an async function which randomally returns true
 */
function doWhat() {
  return new Promise((resolve, reject) => {
    setTimeout(function () {
      resolve(Math.random() > 0.8);
    }, 1000);
  });
}

/**
 * Checks whether a condition is met, in order to tell waitUntil to proceed
 * @param {object} data - The response from the business function above
 */
function untilWhen(data) {
  return data === true;
}

waiter
  .waitUntil(doWhat, untilWhen)
  .then(isTrue => console.log('Condition finally met!'));

Readme

Keywords

none

Package Sidebar

Install

npm i node-waiter

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

2.98 kB

Total Files

4

Last publish

Collaborators

  • nire0510