1 00:00:01,230 --> 00:00:02,250 Welcome back, ladies and gentlemen. 2 00:00:02,280 --> 00:00:06,840 Today, we're going to talk about new iOS nine features there finally. 3 00:00:06,840 --> 00:00:11,670 And for a weight off a off in this, we have done this one in previous. 4 00:00:11,700 --> 00:00:19,100 These two links are for you to read in your free time in there for the finally and for a wait of OK, 5 00:00:19,500 --> 00:00:21,060 so they are MDM links. 6 00:00:21,670 --> 00:00:27,060 And now before we do this, we need to do one example. 7 00:00:27,060 --> 00:00:27,930 We promise that. 8 00:00:27,930 --> 00:00:30,750 OK, so we're going to do a six. 9 00:00:32,940 --> 00:00:33,690 Promises. 10 00:00:36,770 --> 00:00:45,680 And we're going to use a promise that, oh, OK, but for doing that, we need to have this Pokémon 11 00:00:45,680 --> 00:00:46,370 API. 12 00:00:46,400 --> 00:00:49,810 This is a restfully API and we need this link here. 13 00:00:49,820 --> 00:00:50,600 So open up. 14 00:00:52,080 --> 00:00:59,190 Type Pokémon that Apple and Google, and this should be the first thing that you see POC API now from 15 00:00:59,190 --> 00:00:59,560 here. 16 00:01:00,030 --> 00:01:07,490 You just grab the ability, grab this part and create a const you URL's. 17 00:01:07,920 --> 00:01:15,330 This will be an array of four different URLs because we're going to need them so we can loop and let's 18 00:01:15,330 --> 00:01:19,440 grab at this one here ability and we're going to start from one. 19 00:01:19,530 --> 00:01:23,680 OK, so we're going to loop this using the map method. 20 00:01:23,700 --> 00:01:24,170 OK. 21 00:01:25,770 --> 00:01:31,170 And the reason why I'm showing you this, well, because we I need to show you how finally is working. 22 00:01:31,410 --> 00:01:33,330 So three you know, four. 23 00:01:33,330 --> 00:01:33,930 Nice. 24 00:01:34,470 --> 00:01:35,920 Get rid of that comma over there. 25 00:01:36,270 --> 00:01:36,660 Good. 26 00:01:36,990 --> 00:01:44,090 Now go back to your lecture for grap this promise that all and we're going to change it a little bit. 27 00:01:44,100 --> 00:01:47,760 So if you don't know what what about what this promise that always doing. 28 00:01:48,240 --> 00:01:53,310 Just go back, watch the lecture about promises here instead of passing Jason else. 29 00:01:53,700 --> 00:01:54,900 I'm just going to pass this. 30 00:01:54,900 --> 00:02:05,970 You are wrestling here and it should be you or else not you are as crazy and instead of response, just 31 00:02:06,510 --> 00:02:06,930 change it. 32 00:02:06,930 --> 00:02:11,540 The ability because we are we were getting the ability and that's it. 33 00:02:11,700 --> 00:02:20,220 This using map method on this array and we are fetching each and every year on each and every loop. 34 00:02:20,430 --> 00:02:23,340 This will return us for promises. 35 00:02:23,610 --> 00:02:26,760 This is how we just consume the promises and not quite. 36 00:02:26,790 --> 00:02:28,760 Well let's change them. 37 00:02:29,550 --> 00:02:32,310 Let's say Pokémon one. 38 00:02:34,460 --> 00:02:36,890 And let's put a comma here. 39 00:02:39,390 --> 00:02:46,380 So we have four Pokemon's that we need to worry about it right at the moment, we are doing one, two 40 00:02:47,010 --> 00:02:48,080 and three. 41 00:02:48,240 --> 00:02:55,490 Now, I need to call this one, changed this to three because this will return an array of four. 42 00:02:56,010 --> 00:03:02,000 OK, now go back here, make sure that you create lecture and link it in your index file. 43 00:03:02,010 --> 00:03:02,450 OK? 44 00:03:03,930 --> 00:03:08,070 I really don't want to say this, but the students are jumping now. 45 00:03:08,290 --> 00:03:13,760 I do have the result back and I have Pokémon one and there are a lot of things inside. 46 00:03:14,130 --> 00:03:16,440 OK, instead of that, just. 47 00:03:18,330 --> 00:03:25,080 Do this, that name now I do have Pokémon one stench, the ability to stench. 48 00:03:25,110 --> 00:03:29,380 Well, then the other one is drizzle speed boost in battle armor. 49 00:03:29,670 --> 00:03:30,390 Nice. 50 00:03:30,540 --> 00:03:33,040 Now we know the Pokemon's ability. 51 00:03:33,090 --> 00:03:37,580 You can read more about these Apache restfully appear in your free time. 52 00:03:37,590 --> 00:03:40,770 And if it's not working, then use JSON placeholder. 53 00:03:40,780 --> 00:03:41,490 I'm just joking. 54 00:03:41,490 --> 00:03:41,990 Should work. 55 00:03:42,690 --> 00:03:44,040 So what's happening here? 56 00:03:44,070 --> 00:03:53,840 OK, now we are using promise that all and if there is any error here, let's do this through error. 57 00:03:55,260 --> 00:03:57,030 So let's see what's happening. 58 00:03:57,540 --> 00:04:00,780 We will see this error right now. 59 00:04:01,200 --> 00:04:04,230 What we can do, we can do something a little bit better than this. 60 00:04:04,240 --> 00:04:05,220 I'm just going to close this one. 61 00:04:05,220 --> 00:04:06,240 I don't need it anymore. 62 00:04:09,040 --> 00:04:12,560 So the area is working, we are catching errors if there are some things happening. 63 00:04:12,910 --> 00:04:15,530 OK, but what about this finally? 64 00:04:15,880 --> 00:04:16,330 Right. 65 00:04:16,390 --> 00:04:18,130 So how are we going to use this finally? 66 00:04:18,160 --> 00:04:19,570 Well, it's very simple. 67 00:04:19,570 --> 00:04:30,070 Just add one more line here and say finally and inside is finally, let's create an error function in 68 00:04:30,070 --> 00:04:32,440 console lock. 69 00:04:34,240 --> 00:04:34,900 Finally. 70 00:04:38,350 --> 00:04:41,260 Finished, you can put whatever you want here. 71 00:04:42,430 --> 00:04:45,020 And if you save it, you will see finally finished. 72 00:04:45,700 --> 00:04:47,610 So why what is this finally? 73 00:04:48,040 --> 00:04:54,940 So no matter what happens with the promises, finally will be always called whatever the promise is 74 00:04:54,940 --> 00:04:56,350 resolved or rejected. 75 00:04:56,380 --> 00:05:00,490 So does a matter of the outcome of the promise we have for here. 76 00:05:00,520 --> 00:05:00,850 Right. 77 00:05:01,150 --> 00:05:05,820 If even if it was one, this finally will always be executed. 78 00:05:06,550 --> 00:05:11,360 Now, even if we throw an error here, let's do this through. 79 00:05:11,410 --> 00:05:15,220 This is how you're going to throw a force reprogrammed through an error. 80 00:05:15,410 --> 00:05:18,720 Here is the error occurred in this line, was there? 81 00:05:18,730 --> 00:05:22,230 But even this doesn't matter if there is an error. 82 00:05:22,270 --> 00:05:23,750 This one still executed. 83 00:05:23,980 --> 00:05:26,410 So finally, it's doing this. 84 00:05:26,710 --> 00:05:28,450 So that's why it's called finality. 85 00:05:28,450 --> 00:05:33,220 Whatever happened before, I want this piece of code here to be executed. 86 00:05:33,760 --> 00:05:34,140 Right. 87 00:05:34,600 --> 00:05:39,650 Does it matter if the promise was resolved or rejected? 88 00:05:40,180 --> 00:05:41,970 That is pretty much the finally. 89 00:05:42,250 --> 00:05:45,970 And you can read more about the finally on the link here. 90 00:05:47,380 --> 00:05:47,790 Nice. 91 00:05:48,400 --> 00:05:54,550 Now, the finally does not take parameters here, so you can put it here data save it. 92 00:05:55,420 --> 00:05:57,310 And if I conjola the data. 93 00:06:00,400 --> 00:06:06,040 So he's going to give me back undefiled so it does not take a data or from the promise, the promise 94 00:06:06,040 --> 00:06:08,360 will not give access to any data here. 95 00:06:08,410 --> 00:06:08,760 Right. 96 00:06:09,100 --> 00:06:12,600 And somebody will say, well, why we need to use this. 97 00:06:13,390 --> 00:06:16,870 So finally is not getting data, but it runs at least once. 98 00:06:16,870 --> 00:06:17,200 Right. 99 00:06:17,830 --> 00:06:22,790 So this is something that we want to do at least once. 100 00:06:23,230 --> 00:06:24,970 So, for example, you have a piece of code. 101 00:06:26,130 --> 00:06:32,380 And you want to that piece of code to be executed at the end of the promise, no matter what. 102 00:06:32,700 --> 00:06:35,290 That's where finally power is. 103 00:06:35,640 --> 00:06:42,540 So we want that final piece of code to be executed, no matter what of the outcome of this promise is 104 00:06:43,110 --> 00:06:43,480 nice. 105 00:06:44,340 --> 00:06:52,800 So that is pretty much it now for why I give you this promise that all like this when we have learned 106 00:06:52,800 --> 00:06:56,370 the async functions in our lecture seven. 107 00:06:56,370 --> 00:06:56,650 Right. 108 00:06:58,740 --> 00:06:59,100 Well. 109 00:07:00,250 --> 00:07:08,610 Let's do something here, so let's convert the promise that we have back to what to async function, 110 00:07:08,620 --> 00:07:09,150 OK? 111 00:07:10,330 --> 00:07:16,630 Convert the example to async. 112 00:07:19,040 --> 00:07:20,130 Function, OK? 113 00:07:20,150 --> 00:07:21,170 Now, how are we going to do this? 114 00:07:21,440 --> 00:07:30,020 So I'm going to create CONSED and I will say get Pokemon's, you can say get Pokemon's ability here 115 00:07:30,380 --> 00:07:33,800 and this will be an async function, right. 116 00:07:35,000 --> 00:07:35,460 Good. 117 00:07:35,480 --> 00:07:40,340 Now, we just going to call this async function outside. 118 00:07:42,700 --> 00:07:46,610 Get Pokemon's nice, it will not take any parameters. 119 00:07:46,960 --> 00:07:53,260 So here, what I will do is I'm just going to comment before this error because we don't know, we don't 120 00:07:53,260 --> 00:07:56,040 want to throw it copy and commented back. 121 00:07:56,490 --> 00:07:57,010 OK. 122 00:07:58,290 --> 00:08:00,630 Now, let's face it, this one here. 123 00:08:01,780 --> 00:08:03,010 So what will happen? 124 00:08:03,310 --> 00:08:05,250 Well, we need to change a couple of things. 125 00:08:06,550 --> 00:08:09,170 First, we need to have try and catch block, right? 126 00:08:09,340 --> 00:08:11,230 Well, let's first change a couple of things. 127 00:08:11,440 --> 00:08:12,820 Now I'm going to create const. 128 00:08:15,220 --> 00:08:16,960 And I'm going to say Pokémon. 129 00:08:19,210 --> 00:08:26,890 I'm going to create Pokémon, I'm going to create four constants, so there will be for these four things 130 00:08:26,890 --> 00:08:27,180 here. 131 00:08:27,190 --> 00:08:31,600 OK, one, two, three and four, and they should be two. 132 00:08:32,630 --> 00:08:35,780 Three and four nights. 133 00:08:36,900 --> 00:08:40,830 So get rid of this comment and that will be equal to. 134 00:08:42,780 --> 00:08:43,380 Is that OK? 135 00:08:43,410 --> 00:08:49,710 But when we have a promise that we always used a wait right before the promises, we can use a wait 136 00:08:50,220 --> 00:08:57,090 and promise that all but here last time I didn't tell you how we can change all of this and make it 137 00:08:57,090 --> 00:08:58,500 back to look like. 138 00:08:59,930 --> 00:09:05,870 So I'm just going to get rid of this part here because we don't need it now, last time I didn't tell 139 00:09:05,870 --> 00:09:11,660 you how we can change this part to be async as well and get rid of these then Cheney. 140 00:09:11,750 --> 00:09:13,280 OK, so how we can do this? 141 00:09:13,520 --> 00:09:17,740 Well, in order to do this, this is a function that takes one parameters. 142 00:09:17,750 --> 00:09:18,000 Right. 143 00:09:18,200 --> 00:09:20,810 So you URL's up map and we have a function here. 144 00:09:20,990 --> 00:09:26,510 Even if you do this, it will not throw an error because this is a function that takes a one parameter. 145 00:09:26,510 --> 00:09:34,640 And what we can do, we can say async function, because if we want to use a wait inside, this function 146 00:09:34,640 --> 00:09:39,690 needs to be an async and it will not be an error function anymore. 147 00:09:40,220 --> 00:09:43,970 So here what we can do, we can say const response. 148 00:09:45,250 --> 00:09:46,090 Equal to. 149 00:09:48,780 --> 00:09:52,000 Await the fetch you, Earl. 150 00:09:52,060 --> 00:09:52,620 That's it. 151 00:09:53,100 --> 00:09:57,030 So we are done until this part, then I have to return. 152 00:10:00,740 --> 00:10:01,340 Which is going to. 153 00:10:03,770 --> 00:10:07,700 Delete this one, this part, and here I'm going to return the data. 154 00:10:08,020 --> 00:10:15,220 So data will be equal to await response that. 155 00:10:15,400 --> 00:10:17,700 Jason, let me finish this one real quick. 156 00:10:18,400 --> 00:10:19,440 Very good. 157 00:10:19,690 --> 00:10:24,010 So I'll say here, let's cancel log. 158 00:10:26,140 --> 00:10:28,750 Pokémon one, that name. 159 00:10:29,230 --> 00:10:31,630 So now we have the access of the Pokemon's. 160 00:10:31,660 --> 00:10:36,070 OK, and we can see here Volkman one. 161 00:10:38,580 --> 00:10:46,980 Comma there, so we can copy this and pasted three more times because we need four for Pokemon's, so 162 00:10:46,980 --> 00:10:51,240 this should be these should be two, right? 163 00:10:52,790 --> 00:10:54,920 Should be three. 164 00:10:56,670 --> 00:11:01,170 And they should be for there you go. 165 00:11:02,270 --> 00:11:08,600 Now, let's save it and go back to your it is Pokémon stench. 166 00:11:09,900 --> 00:11:11,220 Let's change this one here. 167 00:11:13,100 --> 00:11:18,960 Let's change it to this, because I don't want to be identical as the other one, so some students will 168 00:11:18,960 --> 00:11:21,090 confuse it because they will think, OK, it's the same. 169 00:11:21,090 --> 00:11:21,720 It's not saying same. 170 00:11:21,970 --> 00:11:22,320 It is. 171 00:11:22,470 --> 00:11:23,770 It's working, OK. 172 00:11:24,120 --> 00:11:28,410 Now, if we have an error, remember, we did try and catch block. 173 00:11:28,920 --> 00:11:37,970 So try then we have the catch and we were catching the error with some error occurred. 174 00:11:38,220 --> 00:11:42,530 Then we use the catch block to print out the error. 175 00:11:46,710 --> 00:11:49,040 And pastie earlier, oops. 176 00:11:52,130 --> 00:11:52,880 Very nice. 177 00:11:53,180 --> 00:11:53,750 That's it. 178 00:11:55,280 --> 00:11:55,860 There you go. 179 00:11:55,880 --> 00:12:00,770 Now, if we have some error, but here, make sure that you don't comment about this one because it 180 00:12:00,770 --> 00:12:01,460 will not work. 181 00:12:01,880 --> 00:12:04,510 OK, so that is pretty much it. 182 00:12:04,760 --> 00:12:15,140 This is how we transform the promise that all using that, then, yes, six to is nine using async single 183 00:12:15,140 --> 00:12:15,420 word. 184 00:12:15,490 --> 00:12:23,570 OK, that is pretty much cool because in the previous lecture I didn't tell you how we can change these 185 00:12:23,570 --> 00:12:23,980 four. 186 00:12:23,990 --> 00:12:24,400 Right. 187 00:12:24,890 --> 00:12:27,200 We just left it as it is using that then. 188 00:12:27,350 --> 00:12:27,770 Nice. 189 00:12:28,190 --> 00:12:29,340 So that is pretty much it. 190 00:12:29,360 --> 00:12:35,600 Now the next part that I want to show you is for our weight off. 191 00:12:36,020 --> 00:12:37,010 But before that. 192 00:12:38,490 --> 00:12:43,220 We need to I need to explain for off loop again, OK? 193 00:12:45,380 --> 00:12:53,750 So we basically we did get rid of the then Cheney and made our promises to look very nice right now, 194 00:12:53,750 --> 00:13:02,110 the new feature, these for a weight off, will allow us to loop over the multiple async await calls. 195 00:13:02,120 --> 00:13:04,160 We have multiple async awake calls here. 196 00:13:04,170 --> 00:13:04,520 Right. 197 00:13:05,330 --> 00:13:09,070 And because we are going through we are looping through this array here. 198 00:13:09,080 --> 00:13:11,000 That's why we have a multiple await calls. 199 00:13:11,570 --> 00:13:11,980 Nice. 200 00:13:12,590 --> 00:13:17,390 So before that, I just want to explain what four off was. 201 00:13:21,850 --> 00:13:26,870 Now, four of the Syntex was just like this, and let me just write it for you. 202 00:13:27,280 --> 00:13:31,030 I want you to have it so you don't waste time looking at. 203 00:13:31,030 --> 00:13:31,870 So what is for? 204 00:13:32,230 --> 00:13:35,350 So for now, inside, we have variable. 205 00:13:37,920 --> 00:13:39,510 Of iterable. 206 00:13:41,530 --> 00:13:46,890 And here we have our statement, Loch Ness. 207 00:13:47,590 --> 00:13:54,970 So what is variable on each iteration of value of different properties assigned to a variable so variable 208 00:13:54,970 --> 00:13:55,890 may be declared. 209 00:13:55,900 --> 00:14:01,570 We can't let were whatever you want right now of what is the iterable? 210 00:14:01,570 --> 00:14:05,650 The ideal is the object whose eatable properties are iterated. 211 00:14:06,100 --> 00:14:10,390 Now, this sounds this might sounds confusing, but let's give you an example. 212 00:14:10,570 --> 00:14:17,530 So I'm going to create a const function called for of loop and it will take the you or else. 213 00:14:18,960 --> 00:14:20,950 These are here of Earles, right? 214 00:14:22,450 --> 00:14:22,960 Nice. 215 00:14:25,460 --> 00:14:34,130 So what we will do is we will use for our loop and I will say let invariable will be you are out of 216 00:14:34,400 --> 00:14:39,410 your house now, it's getting better, right, and console. 217 00:14:41,750 --> 00:14:45,150 So that log and we're going to see you around nice. 218 00:14:46,050 --> 00:14:51,220 So again, now variable iterable are very easy to understand. 219 00:14:51,600 --> 00:14:52,080 So. 220 00:14:53,020 --> 00:14:59,100 On each iteration of value of different property is assigned to a variable, very good, a value means 221 00:14:59,590 --> 00:15:01,930 this value, right, for different values. 222 00:15:02,680 --> 00:15:03,130 Now. 223 00:15:04,140 --> 00:15:12,240 Iterable is an object whose iterable properties are iterated, so this is the object that we are just 224 00:15:12,240 --> 00:15:14,380 looking through right now. 225 00:15:14,610 --> 00:15:20,070 And here we can just use CONSED, let whatever we want, save it. 226 00:15:21,060 --> 00:15:22,590 Let me just close this part. 227 00:15:23,790 --> 00:15:24,320 Let's see. 228 00:15:24,330 --> 00:15:24,940 Here it is. 229 00:15:25,450 --> 00:15:32,950 Now we need to for loop just to call it outside and pass you or else. 230 00:15:33,480 --> 00:15:39,330 OK, now you have them hdb we have four different URLs. 231 00:15:39,540 --> 00:15:45,450 Now you know how the four of Leupp works, so let's use for a wait. 232 00:15:47,540 --> 00:15:48,890 On this, get Pokemon's. 233 00:15:49,080 --> 00:15:54,620 OK, just going to carpentering for a wait here. 234 00:15:59,060 --> 00:15:59,840 Using. 235 00:16:02,080 --> 00:16:09,100 Async OK now, because we already have Pokemon's now, if you don't want to use other name, you can 236 00:16:09,100 --> 00:16:10,780 comment this one, but I don't want it. 237 00:16:11,110 --> 00:16:12,850 So what we can do, I can just. 238 00:16:13,770 --> 00:16:16,500 Do this part, what's happening here? 239 00:16:16,530 --> 00:16:20,670 Probably I didn't copy everything, let me just. 240 00:16:22,750 --> 00:16:23,790 Copy this part again. 241 00:16:24,670 --> 00:16:28,100 Because I have somewhere mistake, but that's all good now. 242 00:16:28,530 --> 00:16:36,670 Now make sure that this is called one and this is called one, they're OK because we need to call it 243 00:16:36,670 --> 00:16:39,180 with different names because we're going to have a problem. 244 00:16:39,250 --> 00:16:40,150 This is a concept. 245 00:16:40,460 --> 00:16:44,620 OK, now let's use this for a weight loop. 246 00:16:44,980 --> 00:16:46,510 So let me just. 247 00:16:48,220 --> 00:16:54,240 Get rid of a couple of parts here, and I'm just going to make your life easier now. 248 00:16:54,880 --> 00:16:56,920 So if I do this, so what are we going to do? 249 00:16:56,930 --> 00:17:05,620 Let's create an array of promises and let's call this array of promises, same promises, array and 250 00:17:05,890 --> 00:17:06,570 in disarray. 251 00:17:06,580 --> 00:17:09,280 We will look through the OR using the map method. 252 00:17:09,280 --> 00:17:11,500 So you earles that map. 253 00:17:12,840 --> 00:17:17,550 And inside, I will have you, Earl, and fetch. 254 00:17:20,740 --> 00:17:24,880 Let's make this one bigger fetch, you are out. 255 00:17:24,920 --> 00:17:28,000 OK, so what we have. 256 00:17:29,130 --> 00:17:34,140 We create the array of promises and we look through the world using the map method. 257 00:17:34,350 --> 00:17:41,610 Now the map method will return a new array to us because every map method returns an array and it will 258 00:17:41,610 --> 00:17:43,890 be stored in these cost promises. 259 00:17:44,400 --> 00:17:52,340 So what we are doing is we are fetching the each array each year out link here. 260 00:17:52,800 --> 00:17:53,160 Right. 261 00:17:54,330 --> 00:17:56,520 So let me just show it to you. 262 00:17:58,520 --> 00:18:05,630 So let's lock these promises, Ari, so see what's inside there, so cancel the lock, save it. 263 00:18:06,020 --> 00:18:08,390 And now I have four promises back. 264 00:18:08,420 --> 00:18:08,900 Why? 265 00:18:09,170 --> 00:18:15,290 Well, the fetch method always returns a promise, but I have a few different promises because I'm mapping 266 00:18:15,290 --> 00:18:21,830 through this array, which contains different four different links. 267 00:18:22,310 --> 00:18:26,300 Now, I do have these four promises back, so we don't need this. 268 00:18:27,550 --> 00:18:35,220 And now the for a loop we can use here for a wait. 269 00:18:35,440 --> 00:18:37,830 This is how it is being called. 270 00:18:38,110 --> 00:18:44,410 And I'm going to say here, let promises or let promise off. 271 00:18:44,710 --> 00:18:45,490 I need to 272 00:18:48,010 --> 00:18:49,360 supply these promises. 273 00:18:50,710 --> 00:18:59,440 OK, now const data, I will say outweight promise dot. 274 00:18:59,800 --> 00:19:00,300 Sorry. 275 00:19:00,580 --> 00:19:01,360 Promise that. 276 00:19:01,360 --> 00:19:03,200 Jason Very good. 277 00:19:03,460 --> 00:19:11,300 And finally I can console lock that data and I can use that name. 278 00:19:11,320 --> 00:19:13,770 OK, now what is happening here. 279 00:19:13,780 --> 00:19:19,270 So we kind of lock, we see that inside this array we have a four promises and we see that the four 280 00:19:19,270 --> 00:19:22,020 hour loop was working very good with those things. 281 00:19:22,210 --> 00:19:24,630 So here we create the variable in iterable. 282 00:19:24,640 --> 00:19:25,900 So here is the scene. 283 00:19:26,080 --> 00:19:28,080 This is the variable called promise. 284 00:19:28,090 --> 00:19:33,760 You can call it anything you want and this is the iterable or the entire rate that we want to look through. 285 00:19:34,090 --> 00:19:44,710 So every promise that is saved in this promise is now we will be able to loop with a wait for a loop. 286 00:19:45,310 --> 00:19:51,120 So to extract here the data now we need to use a wait promise that Jason. 287 00:19:51,460 --> 00:19:54,970 But while we wait while we use a wait in front of promises. 288 00:19:54,970 --> 00:19:55,240 Right. 289 00:19:56,460 --> 00:20:00,130 Because this year we are just accessing each promises in the right. 290 00:20:00,420 --> 00:20:07,170 Now we are awaiting that promise that Jason to resolve and after that, we just counseling one, save 291 00:20:07,170 --> 00:20:09,240 it and let's see what's happening. 292 00:20:09,480 --> 00:20:10,210 There you go. 293 00:20:10,620 --> 00:20:12,530 This was the previous output. 294 00:20:12,570 --> 00:20:14,070 This is the new output. 295 00:20:14,280 --> 00:20:19,320 OK, and we have OK, here it is, the first one. 296 00:20:19,660 --> 00:20:25,410 Now, what's happening with this for a loop or with any function? 297 00:20:25,710 --> 00:20:27,910 We will get the data when it's ready. 298 00:20:27,930 --> 00:20:32,160 Right now, this was before that happened before I get the data. 299 00:20:32,170 --> 00:20:34,810 That's why the stanched save it again. 300 00:20:35,610 --> 00:20:37,020 Now I have stange result. 301 00:20:37,030 --> 00:20:37,860 Then the other one. 302 00:20:39,110 --> 00:20:42,350 When I said the other one, it's coming from these get Pokemon's, OK? 303 00:20:44,030 --> 00:20:45,250 And there you go. 304 00:20:45,560 --> 00:20:47,930 Now you will not be able to see. 305 00:20:49,670 --> 00:20:57,020 For example, line each to be ordered one by another, well, because this is away, it's not going 306 00:20:57,020 --> 00:20:57,880 to block the code. 307 00:20:58,190 --> 00:21:01,230 So if it needs to wait, that's what happened here. 308 00:21:01,370 --> 00:21:06,650 So you've got this two, then you need to wait to get the speed boost in battle armor. 309 00:21:06,830 --> 00:21:11,930 But before it's waiting, other other functions were executed. 310 00:21:12,170 --> 00:21:14,920 That's why it's called asynchronous non blocking code. 311 00:21:14,930 --> 00:21:15,510 Right. 312 00:21:15,560 --> 00:21:16,430 Don't get confuse. 313 00:21:16,940 --> 00:21:20,540 Our functions are working as they should, so they are not blocking the code. 314 00:21:20,750 --> 00:21:23,450 So they are resolved when they get the data. 315 00:21:23,600 --> 00:21:28,150 So here, if I save it again now again, I'm going to have the same one. 316 00:21:28,170 --> 00:21:29,410 OK, let's do it here. 317 00:21:30,350 --> 00:21:32,550 Let's just make sure that this is smaller. 318 00:21:32,630 --> 00:21:33,780 So save it one more time. 319 00:21:33,800 --> 00:21:34,820 Here it is now. 320 00:21:34,820 --> 00:21:36,890 It's different now, but save it one more time. 321 00:21:37,400 --> 00:21:38,240 Different output. 322 00:21:38,660 --> 00:21:39,500 Different output. 323 00:21:40,510 --> 00:21:40,940 Yeah. 324 00:21:41,150 --> 00:21:41,710 Here it is. 325 00:21:41,870 --> 00:21:44,900 Now I have the first function here. 326 00:21:45,050 --> 00:21:47,120 Get Promis, get Pokemon's. 327 00:21:47,600 --> 00:21:53,990 It's been executed and it gave us the data then the second second for a weight. 328 00:21:55,370 --> 00:22:00,530 So this is, this is with the full weight that was executed and gave us the data back to us. 329 00:22:00,560 --> 00:22:00,920 Right. 330 00:22:01,550 --> 00:22:02,980 That's pretty much it. 331 00:22:03,320 --> 00:22:08,690 So for a weight takes each item from the array in weights for it to be resolved. 332 00:22:08,840 --> 00:22:12,590 Sometimes this can can happen and get the first response. 333 00:22:13,250 --> 00:22:16,760 But the second and the second response will be not ready. 334 00:22:17,330 --> 00:22:22,550 But at the end you will see all the responses right in there in the correct order. 335 00:22:22,820 --> 00:22:23,160 Right. 336 00:22:23,510 --> 00:22:28,320 So even if this was moved on top, they're incorrect or a stench drizzle. 337 00:22:28,460 --> 00:22:30,340 It will be like this here. 338 00:22:30,350 --> 00:22:31,490 It is stange result. 339 00:22:31,490 --> 00:22:32,810 But then we have the last two. 340 00:22:33,380 --> 00:22:37,430 OK, these are the features that today we discussed. 341 00:22:37,430 --> 00:22:41,180 There were finally and we can put here finally. 342 00:22:42,380 --> 00:22:42,980 Where was it? 343 00:22:45,240 --> 00:22:50,320 Well, I went too much, so finally it executed no matter what. 344 00:22:50,370 --> 00:22:55,290 So this is good for a piece of code that you want to be executed at the end of each promise. 345 00:22:55,290 --> 00:23:02,490 Doesn't matter if it's fulfilled or rejected, then we have for all we have done a for example, and 346 00:23:02,490 --> 00:23:06,570 after that we have done for a weight off. 347 00:23:06,720 --> 00:23:08,820 OK, so this was for a weight off. 348 00:23:08,820 --> 00:23:13,560 And look how this is cleaner than this one right now. 349 00:23:13,560 --> 00:23:19,960 If you want, you can say here Pokémon, but you can change this cause a little bit. 350 00:23:19,980 --> 00:23:24,870 Not to be nicer, but look this part and see it here. 351 00:23:24,930 --> 00:23:25,320 Right. 352 00:23:26,650 --> 00:23:28,220 That's pretty much it for this lecture. 353 00:23:28,240 --> 00:23:35,110 I hope you like it so we learn about new or latest feature of its nine or 12 and 18.