Giter Site home page Giter Site logo

busterc / promise-do-until Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 6 KB

:loop: Calls a function repeatedly until a condition returns true and then resolves the promise

License: ISC License

JavaScript 100.00%
promise promises promise-library promise-modules es6-promise flow-control

promise-do-until's Introduction

promise-do-until NPM version Build Status Dependency Status

Calls a function repeatedly until a condition returns true and then resolves the promise

Installation

$ npm install --save promise-do-until

Usage

import promiseDoUntil from 'promise-do-until';

let count = 0;

promiseDoUntil(() => {
  count++;
}, () => {
  return count === 5;
}).then(() => {
  console.log(count);
  // => 5
});

// ...

let max = 0;

promiseDoUntil(() => {
  max++;
}, () => {
  return max > -1;
}).then(() => {
  console.log(max);
  // => 1
});

API

promiseDoUntil(action, condition)

Executes action repeatedly until condition returns true and then resolves the promise. Rejects if action returns a promise that rejects or if an error is thrown anywhere.

action

Type: function

Action to run for each iteration.

You can return a promise and it will be handled.

condition

Type: function

Should return a boolean of whether to continue.

License

ISC © Buster Collings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.