3 ms·
> savePromiseDone && emailPromiseDone ? res.send() : null // sync, will wait until emailPromiseDone and savePromiseDone are defined ie. their functions are done
by ramblerman 7y ago
> savePromiseDone && emailPromiseDone ? res.send() : null // sync, will wait until emailPromiseDone and savePromiseDone are defined ie. their functions are done
I'm not sure this is correct. Getting to this line already implies they are done, as the await will block. You could just put res.send() on this line no?
- xntrk 7y agoMy understanding was that each await would "block" (creates a new function in a then block that will get execed once the promise resolves). if you wanted to run the two in parallel you would have to Promise.all([promise1, promise2]).then(fn)
- Lyrkan 7y agoYep, the comment is wrong, this line won't wait for anything but rather check that both calls resolved to a truthy value. There are also some other incorrect things in that post that makes the code overly complicated, like: > Every async function needs a new Promise, and needs to resolve() That's definitely not needed unless you call something that runs asynchronously without being `async` or returning a standard `Promise` (in which case you could probably use a generic wrapper to convert them to `Promise` objects and avoid having to do that everytime).