Я не хочу ждать отправки электронного письма, прежде чем вернуть данные заказа обратно в клиент.
Код: Выделить всё
async function createOrder(){
try {
//Create the order object
const order = {
productid: 1234
name: "helpful text"
price: "55.00"
}
sendEmail(order); // I dont want to await this
return {
order // Client needs this ASAP without waiting for email to be sent
}
}
catch (e) {
console.error(e);
}
}
< /code>
Функция электронной почты отправляет почту: < /p>
async function sendEmail(payload){
try {
await axios.post('/emailer/send', {
payload
});
}
catch(e){
console.error(e);
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... r-required
Мобильная версия