1
00:00:00,780 --> 00:00:02,790
Let's talk about await method.

2
00:00:03,270 --> 00:00:04,140
Await method.

3
00:00:04,170 --> 00:00:08,100
Work inside the async method to run await method.

4
00:00:08,130 --> 00:00:10,410
First we need to create async function.

5
00:00:10,830 --> 00:00:17,910
As you can see on your screen, we create a async function named test, and inside the function I print

6
00:00:17,940 --> 00:00:19,110
three statement.

7
00:00:19,140 --> 00:00:23,580
If I call this function it going to print three of the statement one by one.

8
00:00:23,910 --> 00:00:27,000
Suppose we have any code after this function.

9
00:00:27,000 --> 00:00:28,950
Then it will print after that.

10
00:00:28,980 --> 00:00:30,880
Let's talk about await method.

11
00:00:30,900 --> 00:00:34,000
We can use await method in our async function.

12
00:00:34,020 --> 00:00:37,790
Just we need to type await keyword before any of the code line.

13
00:00:37,800 --> 00:00:39,210
Something like that.

14
00:00:39,240 --> 00:00:46,410
The meaning of the line is I told my compiler to wait after printing log B what is the advantage of

15
00:00:46,410 --> 00:00:49,510
this until the console process is completed?

16
00:00:49,530 --> 00:00:54,020
Then the code outside of our async function start executing.

17
00:00:54,030 --> 00:01:00,120
If I call the test function, first it going to print console A, then it come to await method.

18
00:01:00,120 --> 00:01:04,170
And here I told my async function to wait it print console b.

19
00:01:04,440 --> 00:01:07,920
After that, whatever code is there, it will not execute it.

20
00:01:07,920 --> 00:01:12,750
So it jumps outside the test function and try to execute our other code.

21
00:01:12,750 --> 00:01:19,140
And when all the other codes are completed, it will come back to await function and it will check whether

22
00:01:19,140 --> 00:01:20,910
our work is done or not.

23
00:01:20,940 --> 00:01:27,140
If our code is complete, then whatever code is there inside the async function, it will start execute.

24
00:01:27,150 --> 00:01:33,960
So when we use await method in async function, it stop executing our function and jump outside the

25
00:01:33,960 --> 00:01:36,660
function and try to execute other codes.

26
00:01:36,660 --> 00:01:42,990
And when other codes are completed, it back to the await method and try to execute and try to execute

27
00:01:42,990 --> 00:01:44,610
other async function code.

28
00:01:44,850 --> 00:01:51,330
Mainly we use it when we want to fetch data from server, and we use it with our fetch method.

29
00:01:51,360 --> 00:01:55,950
Using this fetch method, we can retrieve data from the server.

30
00:01:55,950 --> 00:01:59,040
It may be Json data or text data.

31
00:01:59,250 --> 00:02:07,350
The data we want to fetch from the server may take a while to arrive, and our external code continue

32
00:02:07,350 --> 00:02:10,520
to run until the data came from the server.

33
00:02:10,530 --> 00:02:15,600
When the complete data comes in, it goes back to await function again.

34
00:02:15,810 --> 00:02:19,790
Then we continue to do the following task of our function.

35
00:02:19,800 --> 00:02:26,130
So let's start the practical and see how we can use await method with our async function.
