Exercise 2: Async and Await
Test your ability to handle promises using async and await by solving this exercise.
We'll cover the following
Problem statement
The previous exercise uses promises for the new input file, numbers.txt
. In this exercise, you are required to use async
and await
to modify the code.
The input file numbers.txt
is changed to hold the values 100000 and 500000 on two separate lines.
Now, when the program file index
.js is run, it takes a long time to complete. Modify the code so that the program will time out and exit if the execution takes more than 1 second.
Sample input and output
The input file numbers.txt
and the respective expected output for the file is given below.
Input | Output |
---|---|
100000 500000 | timeout after 1000 MS |
Exercise
Complete the index.js
code using async-await
to get the desired output.
The solution to this challenge is available in the next lesson, but try to solve it yourself first.
Get hands-on with 1400+ tech skills courses.