April 2020
Intermediate to advanced
292 pages
6h 50m
English
With the infrastructure bits in place, we can move onto actually sending the email. Let’s write the handler for the Send command:
| | function createHandlers ({ |
| | justSendIt, |
| | messageStore, |
| | systemSenderEmailAddress |
| | }) { |
| | return { |
| | Send: command => { |
| | const context = { |
| | messageStore, |
| | justSendIt, |
| | systemSenderEmailAddress, |
| | sendCommand: command |
| | } |
| | |
| | return Bluebird.resolve(context) |
| | .then(loadEmail) |
| | .then(ensureEmailHasNotBeenSent) |
| | .then(sendEmail) |
| | .then(writeSentEvent) |
| | // If it's already sent, then we do a no-op |
| | .catch(AlreadySentError, () => {}) |
| | .catch( |
| | SendError, |
| | err => writeFailedEvent(context, err) |
| | ) |
| | } |
| | } |
| | } |
It uses a Promise ...
Read now
Unlock full access