foreachasync.js/test.js

30 lines
717 B
JavaScript
Raw Normal View History

2013-08-06 09:51:22 +00:00
(function () {
"use strict";
var forEachAsync = require('./forEachAsync').forEachAsync
2013-08-06 09:51:22 +00:00
;
forEachAsync([0, 500, 70, 200, 400, 100], function (next, element, i, arr) {
// test that array order is as expected
2013-08-06 09:51:22 +00:00
console.log(element, 'is element', i, 'of', arr.length);
// test that thisness is applied
2013-08-06 09:51:22 +00:00
this[element] = i;
if (i > 2) {
// test that synchronous callbacks don't mess things up
next();
} else {
// test asynchronous callbacks
setTimeout(next, element);
}
2013-08-06 09:51:22 +00:00
}, {}).then(function () {
// test that thisness carries
2013-08-06 09:51:22 +00:00
console.log(this);
}).then(function () {
// test then chaining
console.log("now wasn't that nice?");
2013-08-06 09:51:22 +00:00
});
}());