我有下面的代碼,我想避免嵌套的回調:執行幾個貓鼬查詢:如何使用promise來代替?
app.get '/performers', (req, res) ->
conductor = require('models/conductor').init().model
soloist = require('models/soloist').init().model
orchestra = require('models/orchestra').init().model
chamber = require('models/chamber').init().model
performers = {}
conductor.find {}, (err, result) ->
performers.conductor = result
soloist.find {}, (err, result) ->
performers.soloist = result
orchestra.find {}, (err, result) ->
performers.orchestra = result
chamber.find {}, (err, result) ->
performers.chamber = result
res.json performers
任何想法?
JohnnyHK,你的代碼已經非常完美, 謝謝! – sigmus
你也可以粘貼在JS? – chovy
粘貼在這裏:https://gist.github.com/4014642 @chovy – sigmus