If I invoke promises within resolver or hook funct...
# random
u
If I invoke promises within resolver or hook functions in Graphcool should I wait them to be resolved? example:
Copy code
export default async event => {

  /* ... */

  sgMail.send(msgInfo)
      .then(() => console.log('sgMail is sent'))
      .catch((err) => console.log('sgMail error:', err))

  // Or should I await until it's resolved?
  // await sgMail.send(msgInfo)
  //     .then(() => console.log('sgMail is sent'))
  //     .catch((err) => console.log('sgMail error:', err))


  return event;
};
may I be sure that mail will be sent without
await
?
v
you can’t be sure either with or without
await
. So in this example you can skip await, because it only will lead to longer response time.
u
Thanks, but why can't be sure with
await
?
t
I would recommend one of the following two: - await for the email to be sent and if any error occurs, handle or propagate. This will have longer response time. - Push the task to an external task queue. This allows nearly instant return, and is more robust because retries can be handled more consistently. However, this requires external servers plus the job code.
u
Possibly for the second case it could be enough to create separate resolver in the same service for this task. It will
await
executions and handle errors, not wasting response time 🤔