I'm new with promises and I don't know how to do this. The thing is that I will have a number of elements, and for each I will call a function that has a callback. When all this callbacks had been executed I want to execute another function. Something like this:
var elements = [e1,e2, ...] //I don't know how many will be
for (var i = 0; i < elements.length; i++) {
functionWithCallBack(elements[i] ,function(){
//some magic
})
}
//When all the callbacks had been executed I want to execute this one
var finally = function(i){
//some code
}
I know that the solution is with promises, but I just can't get how to do it. Any advice?? Thanks in advance!!