M
M
Mark3212022-04-09 16:29:26
Node.js
Mark321, 2022-04-09 16:29:26

How to write code synchronously?

Good afternoon, I understand that there is a lot of information on the Internet on this topic. I honestly tried to figure it out myself, but maybe today is a bad day and I can’t figure out how to combine synchronous code in nodejs and asynchronous code.
There are functions
a()
b()
c()
Three functions access the api, get data and write data using fs.writeFileSync
I need these three functions to work asynchronously, and then after they execute the
start() function
How do I block stream and wait for these functions to work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
x_dmitry_x, 2022-04-09
@Mark321

Make functions a, b, c asynchronous (use writeFile from fs/promises)

await Promise.all([a(), b(), c()]);
start();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question