0
通知Q承诺的进展我想用Q
Promise
进步的功能,我有这样的代码,我想赶上进度,当进度为100,则解决Promise
:在Node.js的
var q = require("q");
var a = function(){
return q.Promise(function(resolve, reject, notify){
var percentage = 0;
var interval = setInterval(function() {
percentage += 20;
notify(percentage);
if (percentage === 100) {
resolve("a");
clearInterval(interval);
}
}, 500);
});
};
var master = a();
master.then(function(res) {
console.log(res);
})
.then(function(progress){
console.log(progress);
});
但我得到这个错误:
Error: Estimate values should be a number of miliseconds in the future
为什么?
如果我使用多个承诺一个错误处理程序,这应该工作?现在你说如果一个特定的承诺抛出错误,错误处理函数触发 – Fcoder
我更新了我的答案,以进一步澄清这一点。 – PatrickD
似乎已取消进展:https://github.com/kriskowal/q/wiki/API-Reference#promiseprogressonprogress – Fcoder