2013-08-06 09:51:22 +00:00
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
2013-08-06 10:00:37 +00:00
|
|
|
var forEachAsync = require('./forEachAsync').forEachAsync
|
2013-08-06 09:51:22 +00:00
|
|
|
;
|
|
|
|
|
2013-08-06 10:00:37 +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);
|
2013-08-06 10:00:37 +00:00
|
|
|
|
|
|
|
// test that thisness is applied
|
2013-08-06 09:51:22 +00:00
|
|
|
this[element] = i;
|
2013-08-06 10:00:37 +00:00
|
|
|
|
|
|
|
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 () {
|
2013-08-06 10:00:37 +00:00
|
|
|
// test that thisness carries
|
2013-08-06 09:51:22 +00:00
|
|
|
console.log(this);
|
2013-08-06 10:00:37 +00:00
|
|
|
}).then(function () {
|
|
|
|
// test then chaining
|
|
|
|
console.log("now wasn't that nice?");
|
2013-08-06 09:51:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}());
|