I've been using when.js for promises in node.js. I have a function like the following:
function my_func() {
var d = when.defer();
// Async actions simulated with timeout
setTimeout(function() {
//...
if(error) {
return d.resolve(error);
}
d.resolve(result);
}, 1000)
return d.promise;
}
Which I would call like so:
my_func().then(
function(res) {
//...
},
function(err) {
// Handle error
}
);
How do I do the same thing with ES6 Promises?