diff --git a/docs/docs/api/promise.each.md b/docs/docs/api/promise.each.md index 06423dba4..1fd78f01a 100644 --- a/docs/docs/api/promise.each.md +++ b/docs/docs/api/promise.each.md @@ -37,6 +37,29 @@ Promise.each(fileNames, function(fileName) { }); ``` +A simple usage example +```js +const Promise = require('bluebird'); +const path = require('path'); +const fs = Promise.promisifyAll(require('fs')); +let fileNames = ['a.txt','b.txt','c.txt','d.txt'] + +// All promises will be executed serrialy the next +// iteration will start only after the previous promise is fulfilled +return Promise.each(fileNames, file => { + return fs.readFileAsync(path.resolve(__dirname, file)).then(data => { + console.log(data.toString()); + }) // If you use then or catch here it'll be called after each iteration + + +}).then(arr => { // Will be called after all promises are resolved + // arr will just include the original array + // so resolt hanle should be inside each iteration +}).catch(err => { // Get here if one of the promises was rejected and stop all others + +}) +``` +