-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullcontrol-call-boxing.js
65 lines (62 loc) · 1.62 KB
/
fullcontrol-call-boxing.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Created by Philip A Senger on 4/08/15.
*/
var Promise = require("bluebird");
var makeBoomBoom = true;
/**
* Chaining, and returning Promise.
* ---
*
* This is the best possible solution, because you
* control the flow of the promises.
*
*/
var promise = new Promise(function (resolve, reject) {
console.log('1 start');
resolve({msg: 'hello'});
});
// Chaining
promise
.then(function (result) {
console.log('2', result);
result.newmsg = "hello from 2";
return new Promise(function (resolve, reject) {
resolve( result );
});
})
.then(function (result) {
console.log('3', result);
result.newmsg = "hello from 3";
return new Promise(function (resolve, reject) {
resolve( result );
});
})
.then(function (result) {
console.log('4', result);
result.newmsg = "hello from 4";
return new Promise(function (resolve, reject) {
if (makeBoomBoom) {
throw new Error('Eels in my hovercraft');
}
resolve( result );
});
})
.then(function (result) {
console.log('5', result);
result.newmsg = "hello from 5";
return new Promise(function (resolve, reject) {
resolve( result );
});
})
.then(function (result) {
console.log('6', result);
return new Promise(function (resolve, reject) {
resolve( result );
});
})
.catch(function (e) {
console.error('error:', e);
})
.finally(function () {
console.log('fini.');
});