aboutsummaryrefslogtreecommitdiff
path: root/test/js/promise_set_timeout.t.js
blob: fe908f13ceae4de9dd9366e39ceb0570f9ccff06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*---
includes: [compareArray.js]
flags: []
---*/

var res = [];
function abc() {
    var promise = new Promise(function(resolve, reject) {
        res.push('One');
        resolve();
    });
    res.push('Two');
    promise.then(() => {res.push('Four'); return {num: 'Five'}})
    .then((obj) => {res.push(obj.num);  return {num: 'Six'}})
    .then((obj) => {res.push(obj.num)});
    res.push('Three');
}

abc();
assert.compareArray(res, ['One', 'Two', 'Three']);
setTimeout(() => assert.compareArray(res, ['One', 'Two', 'Three', 'Four', 'Five', 'Six']), 0);