comment about all the things that are being tested
This commit is contained in:
parent
475fb235c5
commit
480909dabb
|
@ -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
20
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?");
|
||||
});
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue