comment about all the things that are being tested

This commit is contained in:
AJ ONeal 2013-08-06 03:00:37 -07:00
parent 475fb235c5
commit 480909dabb
2 changed files with 21 additions and 4 deletions

View File

@ -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`.

20
test.js
View File

@ -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?");
});
}());