We\'re using ECMAScript 6 promises
.
We need to implement progress notifications to the end-user (this is pure UX requirement). I know that other promise
Since only specific instance of promise generates progress, we can monkey patch it on demand, like this:
function reparse(){
let notify
let promise = new Promise(async(resolve,reject)=>{
instanceOfjQueryDeferred.done(()=>{
resolve(100)
}).progress((progress)=>{
notify(progress)
})
})
// here is the monkey patch
promise.progress = (handler)=>{
notify = handler
return promise
}
return promise
}
And use it like this:
reparse().progress((p)=>{
console.log('progress',p)
}).then((progress)=>{
console.log('done',progress)
})