0
說我要發送電子郵件,並查找從數據庫中刪除用戶後,在同一時間推通知到客戶端,我可以寫藍鳥並行獨立任務
User.findById(userId).exec()
.then(() => sendMail())
.then(() => pushNotification())
,但由於pushNotification
沒有按」 t必須在sendMail
之後發生,有沒有其他的方式來寫這個?
說我要發送電子郵件,並查找從數據庫中刪除用戶後,在同一時間推通知到客戶端,我可以寫藍鳥並行獨立任務
User.findById(userId).exec()
.then(() => sendMail())
.then(() => pushNotification())
,但由於pushNotification
沒有按」 t必須在sendMail
之後發生,有沒有其他的方式來寫這個?
var BlueBird = require('bluebird');
User.findById(userId).exec()
.then(() => Bluebird.all([sendMail(), pushNotification()]))
會在同一時間啓動它們並等待它們兩者。
同樣的,ES6:
User.findById(userId).exec()
.then(() => Promise.all([sendMail(), pushNotification()]))