[英]how to convert Async.js parallel to Bluebird
With async.js i can be able to define promises(i know its only functions) with handlers and its give me polymorphism with different handlers also results are seperated .使用 async.js,我可以使用处理程序定义承诺(我知道它的唯一功能),并且它为我提供了具有不同处理程序的多态性,并且结果也是分开的。 Can i do this in bluebird ?
我可以在蓝鸟中做到这一点吗?
async.parallel({
cityPromises: (cb)=>{
City.find({
areaId: {$in:locations.city}
}).then(result=> cb(null,result))
},
townPromises: (cb)=>{
Town.find({
areaId: {$in:locations.town}
}).then(result=>cb(null,result))
},
quarterPromises: (cb)=>{
Quarter.find({
areaId: {$in:locations.quarter}
}).then(result=>cb(null,result))
}
},(err,promises)=>{
let {cityPromises, townPromises, quarterPromises} = promises
})
After researching i made this.经过研究,我做了这个。 http://bluebirdjs.com/docs/api/promise.props.html
http://bluebirdjs.com/docs/api/promise.props.html
let promisesObject ={
cities: City
.find({
areaId: {$in:locations.city}
})
.select({ name: 1, areaId: 1})
.exec(),
towns: Town
.find({
areaId: {$in:locations.town}
})
.select({ name: 1, areaId: 1})
.exec(),
quarters: Quarter
.find({
areaId: {$in:locations.quarter}
})
.select({ name: 1, areaId: 1})
.exec()
}
promise.props(promisesObject)
.then((result) =>{
let {cities, towns, quarters} = result
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.