diff --git a/README.md b/README.md index 4c0464e..ef9c637 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ forEachAsync === -v3.0 - Diet Cola Edition (not yet published to npm) +As I do every few years, I decided to rewrite FuturesJS. +This year's remake is extremely lightweight. + +v3.0 - Diet Cola Edition (not yet published to npm - and don't worry, v2.x is still supported) Analogous to `[].forEach`, but handles items asynchronously with a final callback passed to `then`. diff --git a/test.js b/test.js index c881fcd..7c1cfe9 100644 --- a/test.js +++ b/test.js @@ -1,15 +1,29 @@ (function () { "use strict"; - var forEachAsync = require('../forEachAsync').forEachAsync + var forEachAsync = require('./forEachAsync').forEachAsync ; - forEachAsync([0, 500, 70, 800], function (next, element, i, arr) { + forEachAsync([0, 500, 70, 200, 400, 100], function (next, element, i, arr) { + // test that array order is as expected console.log(element, 'is element', i, 'of', arr.length); + + // test that thisness is applied this[element] = i; - setTimeout(next, element); + + if (i > 2) { + // test that synchronous callbacks don't mess things up + next(); + } else { + // test asynchronous callbacks + setTimeout(next, element); + } }, {}).then(function () { + // test that thisness carries console.log(this); + }).then(function () { + // test then chaining + console.log("now wasn't that nice?"); }); }());