fixed order bug

This commit is contained in:
AJ ONeal 2015-01-02 18:39:27 -07:00
parent 8daeae0e1d
commit 70eda0ad55
4 changed files with 24 additions and 12 deletions

View File

@ -30,7 +30,7 @@
ret = PromiseA.resolve(result);
}
ret.then(function (val) {
return ret.then(function (val) {
if (val === forEachAsync.__BREAK) {
return PromiseA.reject(new Error('break'));
//throw new Error('break');

View File

@ -1,6 +1,6 @@
{
"name": "foreachasync",
"version": "5.0.1",
"version": "5.0.2",
"description": "A node- and browser-ready async (now with promises) counterpart of Array.prototype.forEach",
"homepage": "https://github.com/FuturesJS/forEachAsync",
"main": "forEachAsync.js",

View File

@ -7,21 +7,28 @@
;
forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) {
// test that array order is as expected
console.log(element, 'is element', i, 'of', arr.length);
console.log(i, '/', arr.length, 'began');
var result
;
// test that thisness is applied
this[element] = i;
if (i > 2) {
if (i % 2) {
// test that synchronous callbacks don't mess things up
return PromiseA.resolve();
result = PromiseA.resolve();
} else {
// test asynchronous callbacks
return new Promise(function (resolve/*, reject*/) {
result = new Promise(function (resolve/*, reject*/) {
setTimeout(resolve, element);
});
}
return result.then(function () {
// test that array order is as expected
console.log(i, '/', arr.length, 'complete');
});
}, context).then(function () {
// test that thisness carried
console.log('context', context);

View File

@ -6,21 +6,26 @@
;
forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) {
// test that array order is as expected
console.log(element, 'is element', i, 'of', arr.length);
var p
;
// test that thisness is applied
this[element] = i;
if (i > 2) {
if (i % 2) {
// test that synchronous callbacks don't mess things up
return Promise.resolve();
p = Promise.resolve();
} else {
// test asynchronous callbacks
return new Promise(function (resolve/*, reject*/) {
p = new Promise(function (resolve/*, reject*/) {
setTimeout(resolve, element);
});
}
return p.then(function () {
// test that array order is as expected
console.log(element, 'is element', i, 'of', arr.length);
});
}, context).then(function () {
// test that thisness carried
console.log('context', context);