How do I convert an existing callback API to promises?

Ask a question
0

I want to work using promises but I have a callback API in this format:

1. DOM load or other one time event:

 // set to callback
window.onload;
…
.onload = function() {

};

2. Plain callback:

function request(onChangeHandler) {
…
}
(function() {
// change happened
…
});

3. Node style callback (“nodeback”):

function getStuff(dat, callback) {
…
}
(“dataParam”, function(err, data) {
…
})

4. A whole library with node style callbacks:

API;
.one(function(err, data) {
.two(function(err, data2) {
.three(function(err, data3) {
…
});
});
});

How do I work with the API in promises, how do I “promisify” it?

Coin iconoffer bounty
add comment

0 Answer

Your Answer