1
使用Balderdashy/Waterline和Caolan/Async,我試圖並行化severa Waterline查詢。到現在爲止,我發現越短如下:Nodejs:Waterline + Caolan/Async:綁定函數
const tasks = {
foos: (function(){return this.exec.bind(this);}).apply(Foo.find({foo: "foo"})),
bars: (function(){return this.exec.bind(this);}).apply(Bar.find({bar: "bar"}))
};
return async.parallel(tasks, function(err, out){
// Here, err contains the potential error, and out looks like {foos:[...],bars:[...]}
});
我試圖做bars: Bar.find({bar: "bar"}).exec
但async
似乎apply
與另一個對象範圍的功能。所以我無法找到一個方法來做到這在一個更簡單/更簡單的方式。
請注意,我想避免自己包裹在其他的功能,因爲它是我要找到替代的語法:
bars: function(cb){Bar.find({bar: "bar"}).exec(cb)}
謝謝您的幫助。
這幾乎是我需要什麼?如果只是出結果可能會與比任務相同密鑰的dictionnary返回,這將是絕對完美的。 –
@AlexandreGermain:'bluebird.props({foos:...,bars:...})'代替'Promise.all',然後。 (見編輯!) – Ryan
哦,是的,你是對的。 Bluebird和延期工作都像一個魅力,非常感謝你! –