Async While
This is a small utility for generating while loops with ES6 Promises.
Install
Download a UMD bundle from the releases page. The variable asyncWhile
will be attached to window
.
If using Browserify or Node.js, you can install via NPM.
$ npm install async-
Usage
First, load async while. By default, the global Promise object is used, but you can create a while generator with a custom Promise class, too.
// simplevar asyncWhile = ; // while with Bluebird promisesvar Promise = ;var asyncWhile = ;
Now, generate a while function with asyncWhile
. You'll need two functions: a synchronous condition and an action.
var myWhile = ;
This is just a method that can be called directly or used in .then()
statements.
; // or;
Here is a common use case of the while loop, processing list items in a series:
{ var index = -1; return ;}