2015-08-24 66 views
0

說我要發送電子郵件,並查找從數據庫中刪除用戶後,在同一時間推通知到客戶端,我可以寫藍鳥並行獨立任務

User.findById(userId).exec() 
.then(() => sendMail()) 
.then(() => pushNotification()) 

,但由於pushNotification沒有按」 t必須在sendMail之後發生,有沒有其他的方式來寫這個?

回答

2
var BlueBird = require('bluebird'); 

User.findById(userId).exec() 
    .then(() => Bluebird.all([sendMail(), pushNotification()])) 

會在同一時間啓動它們並等待它們兩者。

0

同樣的,ES6:

User.findById(userId).exec() 
    .then(() => Promise.all([sendMail(), pushNotification()]))