-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-bluebird.js
39 lines (33 loc) · 989 Bytes
/
test-bluebird.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(function () {
"use strict";
var PromiseA = require('bluebird')
, forEachAsync = require('./forEachAsync').forEachAsync
, context = {}
;
forEachAsync([0, 500, 70, 200, 400, 100], function (element, i, arr) {
console.log(i, '/', arr.length, 'began');
var result
;
// test that thisness is applied
this[element] = i;
if (i % 2) {
// test that synchronous callbacks don't mess things up
result = PromiseA.resolve();
} else {
// test asynchronous callbacks
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);
}).then(function () {
// test then chaining
console.log("now wasn't that nice?");
});
}());