需要jQuery's "when"mpromise/mongoose的功能
Need jQuery's "when" functionality for mpromise/mongoose
是否存在不承诺/猫鼬的when条款?我希望做这样的事情,而不必为mpromise编写自己的包装器。
$.when(jQueryPromise1,jQueryPromise3,jQueryPromise3).done(function(r1,r2,r3) {
// success code
}.fail(function(err1,err2,err3) {
//failure code
});
我意识到锁链的存在,那不是我想要的。我正在寻找一个机制,在不承诺/猫鼬,将执行当所有的承诺已经完成。
下面是when的示例实现:
function when(/* promise list */) {
var promises = [].slice.call(arguments),
whenPromise = new Promise,
results = new Array(promises.length),
remaining = promises.length,
done = false,
finish = function() {
done = true;
};
whenPromise.onFulfill(finish).onReject(finish);
promises.forEach(function(promise) {
promise.onFulfill(function(result) {
if (!done) {
// index of result should correspond to original index of promise
results[promises.indexOf(promise)] = result;
if (--remaining == 0) {
// fulfill when all are fulfilled
whenPromise.fulfill.apply(whenPromise, results);
}
}
}).onReject(function(err) {
if (!done) {
// reject when one is rejected (a la jQuery)
whenPromise.reject(err);
}
});
});
}
相关文章:
- 使用promise和mongoose对文档进行排序
- 铬:“;未捕获的语法错误:意外的标记:"
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 如何缩短MongoDB ObjectId并在Mongoose模式中使用它
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- 使用“+="操作人员
- //而不是在src=“”上使用http://"属性
- "未捕获的语法错误:意外的标记}"
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- "实例范围”;TypeScript类的getter/setter
- Javascript复选框函数:;缺少:在属性id之后"
- "“;变量未引用正确的对象
- mongoose.connect undefined不是一个函数
- "日期“;AJAX请求返回的类型值未定义
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- "工具提示"jQuery插件坏了
- "锻造;React中的表达式
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部