Yes, you can do this, and it will run two asynchronous functions in parallel. You just made a promise and threw it away.
However, this means that when the promise is rejected, you will not notice. You just get unhandledRejection in the end .
This is normal? How can I run something that I don't care?
Perhaps this is not OK. If you really do not care, you did not run it in the first place. Therefore, you must be clear and clear about what you care about (and what not):
- Do you want to wait? (for side effects)
- Do you need a result?
- Do you want to catch exceptions?
If you only want to wait and not care about the meaning of the result, you can easily discard the result:
void (await someAsyncFunction());
If you don't care about exceptions, you can ignore them using
β¦ someAsyncFunction().catch(function ignore() {}) β¦
You can throw it away, wait, do something with it.
If you want to get a result, you have to wait for it. If you are worried about exceptions but donβt want to wait, you can run it in parallel with the following functions:
var [_, res] = await Promise.all([ someAsyncFunction(),
Bergi
source share