forked from AfterShip/node-tmfy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.js
30 lines (26 loc) · 762 Bytes
/
sample.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
var tmfy = require('./index');
var lib = {
sendEmail: function(send_to) {
// need 200ms to send
return new Promise(function (r) { setTimeout(r, 200) });
},
sendEmailSlowly: function(send_to) {
// need 20000ms to send
return new Promise(function (r) { setTimeout(r, 20000) });
}
};
tmfy.timeifyAll(lib);
lib.sendEmailTimeout(1000, '[email protected]') // timeout after 1000ms
.then(function(result) {
console.log('email sent');
})
.catch(function(error) {
// never called
});
lib.sendEmailSlowlyTimeout(1000, '[email protected]') // timeout after 1000ms
.then(function(result) {
// never called
})
.catch(function(error) {
console.log('timeout first');
});