Await sleep javascript9/1/2023 ![]() ![]() The execution will start from the sleep() function. The below code has 3 function func_1, func_2 and sleep() function. ![]() Let’s first see what happens when we don’t use promise, async, and await in our program. Implement a sleep() Function Without Promise, async and await in JavaScript Using async, we make that function asynchronous. Whenever we request a resource, then there are two things either our request will be fulfilled or it can get rejected. A Promise is an event that tells us whether a request is resolved or rejected. To achieve this, JavaScript provides us with a Promise object and some keywords like async and await. With this, we can effectively make use of the JavaScript engine. Later, we can come back and show the API call results as soon as we get the response back from the server. During that time, we will try to complete other tasks. This will make that function asynchronous, and then with the help of await, we will wait for some time. Instead of waiting for the response, we can add the async keyword before that function that is making the API call which will return a Promise object. Let’s say we are performing an API call then, it might take some time to get the response back from the server. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |