All language subtitles for 18. Consuming Promises with AsyncAwait

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:01,460 --> 00:00:04,280 So now that you're super comfortable with 2 2 00:00:04,280 --> 00:00:08,120 consuming premises and also building premises, 3 3 00:00:08,120 --> 00:00:13,050 let's turn our attention back to actually consuming premises 4 4 00:00:13,050 --> 00:00:14,010 that's because 5 5 00:00:14,010 --> 00:00:14,843 since ES 6 6 00:00:14,843 --> 00:00:16,550 2017, 7 7 00:00:16,550 --> 00:00:20,070 there is now an even better and easier way to consume 8 8 00:00:20,070 --> 00:00:23,453 premises, which is called a sync await. 9 9 00:00:25,200 --> 00:00:27,870 So let me show you how it works. 10 10 00:00:27,870 --> 00:00:31,160 So we start by creating a special kind of function, 11 11 00:00:31,160 --> 00:00:33,313 which is an a sync function. 12 12 00:00:35,310 --> 00:00:38,550 So in this lecture, we will basically recreate the, 13 13 00:00:38,550 --> 00:00:41,493 where am I function that we have been building? 14 14 00:00:42,550 --> 00:00:43,650 Where 15 15 00:00:43,650 --> 00:00:44,483 am I 16 16 00:00:45,400 --> 00:00:46,930 and so function, 17 17 00:00:46,930 --> 00:00:50,803 but for now we will pass in the country again, 18 18 00:00:51,660 --> 00:00:54,040 to make it simple at the beginning. 19 19 00:00:54,040 --> 00:00:55,280 But as I was saying, 20 20 00:00:55,280 --> 00:00:58,530 we now need to make this a special kind of function, 21 21 00:00:58,530 --> 00:01:00,980 which is an a sync function. 22 22 00:01:00,980 --> 00:01:02,940 And we do this by simply adding 23 23 00:01:02,940 --> 00:01:04,300 a sync 24 24 00:01:04,300 --> 00:01:05,650 here in front of the 25 25 00:01:05,650 --> 00:01:06,687 function. 26 26 00:01:06,687 --> 00:01:10,600 And so this function is now an asynchronous function. 27 27 00:01:10,600 --> 00:01:13,660 So a function that will basically keep running in the 28 28 00:01:13,660 --> 00:01:18,330 background while performing the code that inside of it, 29 29 00:01:18,330 --> 00:01:20,400 then when this function is done, 30 30 00:01:20,400 --> 00:01:22,960 it automatically returns a premise, 31 31 00:01:22,960 --> 00:01:26,210 but more on that in the next video 32 32 00:01:26,210 --> 00:01:27,043 for now, 33 33 00:01:27,043 --> 00:01:30,500 what's important is that inside an a sync function, 34 34 00:01:30,500 --> 00:01:33,693 we can have one or more await statements, 35 35 00:01:35,140 --> 00:01:36,760 so, await, 36 36 00:01:36,760 --> 00:01:38,660 and then here we need a premise. 37 37 00:01:38,660 --> 00:01:42,840 And so we can use the premise returned from the fetch 38 38 00:01:42,840 --> 00:01:44,360 function 39 39 00:01:44,360 --> 00:01:46,780 and so let's know, use or API again, 40 40 00:01:46,780 --> 00:01:49,503 to search for a country basically. 41 41 00:01:50,750 --> 00:01:54,780 So let's see where we have some information about that. 42 42 00:01:54,780 --> 00:01:56,580 And here we go. 43 43 00:01:56,580 --> 00:02:00,288 So this is the URL that we have been using. 44 44 00:02:00,288 --> 00:02:03,733 So make sure you grab it somewhere from your code. 45 45 00:02:05,090 --> 00:02:07,923 And so here, let's now pass in this country again. 46 46 00:02:09,300 --> 00:02:10,650 All right. 47 47 00:02:10,650 --> 00:02:13,820 So again, this year we'll return a premise. 48 48 00:02:13,820 --> 00:02:16,335 And so in an a sync function like this one, 49 49 00:02:16,335 --> 00:02:20,600 we can use the await keyword to basically await for the 50 50 00:02:20,600 --> 00:02:23,070 result of this premise. 51 51 00:02:23,070 --> 00:02:27,170 So basically await will stop decode execution at this 52 52 00:02:27,170 --> 00:02:31,280 point of the function until the premise is fulfilled. 53 53 00:02:31,280 --> 00:02:34,993 And so until the data has been fetched in this case, 54 54 00:02:36,410 --> 00:02:38,650 but now after that explanation, 55 55 00:02:38,650 --> 00:02:41,650 you might think isn't stopping the code, 56 56 00:02:41,650 --> 00:02:44,020 blocking the execution? 57 57 00:02:44,020 --> 00:02:47,090 Well, that's a really good question, 58 58 00:02:47,090 --> 00:02:50,440 but the answer is actually no, in this case, 59 59 00:02:50,440 --> 00:02:54,360 because stopping execution in an a sync function, 60 60 00:02:54,360 --> 00:02:58,950 which is what we have here is actually not a problem because 61 61 00:02:58,950 --> 00:03:03,180 this function is running asynchronously in the background. 62 62 00:03:03,180 --> 00:03:07,070 And so therefore it is not blocking the main threat of 63 63 00:03:07,070 --> 00:03:08,420 execution. 64 64 00:03:08,420 --> 00:03:12,690 So it's not blocking the call stack. And in fact, that's, 65 65 00:03:12,690 --> 00:03:16,100 what's so special about a single wait. 66 66 00:03:16,100 --> 00:03:19,990 So it's the fact that it makes our code look like regular 67 67 00:03:19,990 --> 00:03:23,000 synchronous code while behind the scenes. 68 68 00:03:23,000 --> 00:03:26,690 Everything is in fact asynchronous. 69 69 00:03:26,690 --> 00:03:28,190 All right. 70 70 00:03:28,190 --> 00:03:33,190 But anyway, as soon as this premise here is resolved, 71 71 00:03:33,240 --> 00:03:36,600 then the value of this whole await expression that we have 72 72 00:03:36,600 --> 00:03:41,200 here is going to be the resolved value of the premise. 73 73 00:03:41,200 --> 00:03:44,583 And so we can simply store that into a variable. 74 74 00:03:46,290 --> 00:03:48,560 So let's call it res 75 75 00:03:48,560 --> 00:03:50,640 for response. 76 76 00:03:50,640 --> 00:03:54,820 And then here we can take a look at that response. 77 77 00:03:54,820 --> 00:03:58,570 And just to show you that this function here is actually 78 78 00:03:58,570 --> 00:04:00,120 asynchronous. 79 79 00:04:00,120 --> 00:04:03,163 Let's log something to the console before we call it. 80 80 00:04:05,230 --> 00:04:09,770 So just first, because this should be printed first, right? 81 81 00:04:09,770 --> 00:04:12,570 And then, or actually we should call the function first. 82 82 00:04:13,660 --> 00:04:15,210 So where am I 83 83 00:04:15,210 --> 00:04:16,043 with 84 84 00:04:17,090 --> 00:04:18,410 Portugal? 85 85 00:04:18,410 --> 00:04:19,903 But even by doing this, 86 86 00:04:21,060 --> 00:04:24,540 this console dot log first will be displayed first, 87 87 00:04:24,540 --> 00:04:27,380 because again, this is an a sync function. 88 88 00:04:27,380 --> 00:04:29,590 And so once the function is called, 89 89 00:04:29,590 --> 00:04:32,450 it is then loaded off to the background. 90 90 00:04:32,450 --> 00:04:35,770 And so this Fetcher will be running in the background 91 91 00:04:35,770 --> 00:04:37,890 without blocking or main threat. 92 92 00:04:37,890 --> 00:04:40,600 And so the code will move on to the next line, 93 93 00:04:40,600 --> 00:04:43,363 which is then this console dot log first. 94 94 00:04:44,500 --> 00:04:46,070 All right. 95 95 00:04:46,070 --> 00:04:47,660 And so 96 96 00:04:47,660 --> 00:04:49,790 indeed we got the first 97 97 00:04:49,790 --> 00:04:51,310 printed first 98 98 00:04:51,310 --> 00:04:52,143 and then here, 99 99 00:04:52,143 --> 00:04:54,140 we got the response, 100 100 00:04:54,140 --> 00:04:58,160 but this time we got this response in this really nice and 101 101 00:04:58,160 --> 00:04:59,173 elegant way. 102 102 00:05:00,110 --> 00:05:03,630 So you see here that by using a sync await 103 103 00:05:03,630 --> 00:05:04,790 or asynchronous 104 104 00:05:04,790 --> 00:05:06,020 code here, Oh, 105 105 00:05:06,020 --> 00:05:09,800 really looks and feels like synchronous code. 106 106 00:05:09,800 --> 00:05:13,930 So we can simply await until the value of the premise is 107 107 00:05:13,930 --> 00:05:15,730 returned basically. 108 108 00:05:15,730 --> 00:05:19,880 And then just assign that value to a variable meant that is 109 109 00:05:19,880 --> 00:05:22,470 something that was impossible before. 110 110 00:05:22,470 --> 00:05:26,210 So before we had to mess with callback functions and dead 111 111 00:05:26,210 --> 00:05:28,020 was true in callback hell, 112 112 00:05:28,020 --> 00:05:31,800 but also by consuming premises with the then method. 113 113 00:05:31,800 --> 00:05:35,870 But now with a sync await, that is just completely gone, 114 114 00:05:35,870 --> 00:05:37,090 right? So again, 115 115 00:05:37,090 --> 00:05:40,920 this looks now like normal synchronous code where we simply 116 116 00:05:40,920 --> 00:05:43,570 assign values to a variable, 117 117 00:05:43,570 --> 00:05:47,090 and that makes it so much easier and more clean. 118 118 00:05:47,090 --> 00:05:48,870 In my opinion. 119 119 00:05:48,870 --> 00:05:51,490 Now, before you start using a sync await all 120 120 00:05:51,490 --> 00:05:52,690 over the place, 121 121 00:05:52,690 --> 00:05:57,070 you need to first understand that a sink await is in fact, 122 122 00:05:57,070 --> 00:06:01,980 simply syntactic sugar over the then method in premises. 123 123 00:06:01,980 --> 00:06:06,080 So of course behind the scenes, we are still using premises. 124 124 00:06:06,080 --> 00:06:10,540 We are simply using a different way of consuming them here 125 125 00:06:10,540 --> 00:06:13,730 in this case, but what we have here. 126 126 00:06:13,730 --> 00:06:17,240 So this is essentially exactly the same 127 127 00:06:17,240 --> 00:06:18,073 as doing 128 128 00:06:18,990 --> 00:06:20,080 it the old way, 129 129 00:06:20,080 --> 00:06:21,220 basically. 130 130 00:06:21,220 --> 00:06:23,080 So using then and then res 131 131 00:06:24,680 --> 00:06:26,850 and then console dot log res 132 132 00:06:27,830 --> 00:06:28,803 like we did here. 133 133 00:06:29,860 --> 00:06:31,863 So this is exactly the same. 134 134 00:06:34,080 --> 00:06:35,280 So let's put that here 135 135 00:06:37,290 --> 00:06:38,940 and 136 136 00:06:38,940 --> 00:06:40,320 comment it out of course, 137 137 00:06:40,320 --> 00:06:43,770 because what we are interested in is indeed a sync await 138 138 00:06:43,770 --> 00:06:44,603 right now. 139 139 00:06:45,690 --> 00:06:48,960 So now that we know how a sync await works, 140 140 00:06:48,960 --> 00:06:52,720 it's time to actually recreate the, where am I a function? 141 141 00:06:52,720 --> 00:06:55,410 So first off we need to get the Jason 142 142 00:06:55,410 --> 00:06:56,243 out 143 143 00:06:56,243 --> 00:06:58,770 of this response, 144 144 00:06:58,770 --> 00:07:00,110 right? 145 145 00:07:00,110 --> 00:07:02,330 And so remember on the response, 146 146 00:07:02,330 --> 00:07:03,640 we need to call 147 147 00:07:03,640 --> 00:07:05,250 Jason 148 148 00:07:05,250 --> 00:07:07,760 and remember that this itself returns 149 149 00:07:07,760 --> 00:07:09,100 a new premise. 150 150 00:07:09,100 --> 00:07:12,400 And so previously we would have to return this premise 151 151 00:07:12,400 --> 00:07:15,020 and then chain another then handler. 152 152 00:07:15,020 --> 00:07:17,392 But now this becomes so much easier. 153 153 00:07:17,392 --> 00:07:19,480 All we have to do is to, again, 154 154 00:07:19,480 --> 00:07:22,050 await this and then we can store 155 155 00:07:22,050 --> 00:07:24,620 the results directly into the data 156 156 00:07:24,620 --> 00:07:27,113 variable that we have been using before. 157 157 00:07:30,160 --> 00:07:31,070 Right? 158 158 00:07:31,070 --> 00:07:33,280 And so here it is. 159 159 00:07:33,280 --> 00:07:35,619 So here is the same data as before. 160 160 00:07:35,619 --> 00:07:38,203 And so now all we need to do is to render it. 161 161 00:07:39,480 --> 00:07:40,800 So render country 162 162 00:07:41,650 --> 00:07:43,380 and data 163 163 00:07:43,380 --> 00:07:45,080 at position zero, 164 164 00:07:45,080 --> 00:07:48,810 and in case you skipped any of the previous videos and don't 165 165 00:07:48,810 --> 00:07:51,773 have this render country function, for some reason, 166 166 00:07:51,773 --> 00:07:56,390 you can simply get it from the final files of the section, 167 167 00:07:56,390 --> 00:07:58,310 from the getup repository. 168 168 00:07:58,310 --> 00:08:03,310 So from where you also got the starter files now, okay. 169 169 00:08:03,410 --> 00:08:04,340 And 170 170 00:08:04,340 --> 00:08:05,350 yeah, 171 171 00:08:05,350 --> 00:08:06,760 there is our data 172 172 00:08:06,760 --> 00:08:07,840 so render it 173 173 00:08:07,840 --> 00:08:09,760 to the page here. 174 174 00:08:09,760 --> 00:08:10,600 Great. 175 175 00:08:10,600 --> 00:08:15,600 And all without de-chaining of premises like we had before. 176 176 00:08:15,830 --> 00:08:18,440 So this is really elegant. One more time, 177 177 00:08:18,440 --> 00:08:22,340 simply being able to essentially store the fulfilled premise 178 178 00:08:22,340 --> 00:08:26,550 value immediately into a variable without having to mess 179 179 00:08:26,550 --> 00:08:29,640 with callback functions now. Okay. 180 180 00:08:29,640 --> 00:08:34,220 But now let's actually finish the function here with all the 181 181 00:08:34,220 --> 00:08:36,540 other functionality as well. 182 182 00:08:36,540 --> 00:08:40,313 So with geolocation and also reverse geo coding. 183 183 00:08:41,220 --> 00:08:42,053 So for that, 184 184 00:08:42,053 --> 00:08:45,840 we need to get our premise that we built before for, 185 185 00:08:45,840 --> 00:08:47,223 for geolocation. 186 186 00:08:48,180 --> 00:08:50,763 So this is the one here, 187 187 00:08:51,770 --> 00:08:53,560 so let's get it. 188 188 00:08:53,560 --> 00:08:54,820 And so 189 189 00:08:54,820 --> 00:08:55,653 again, 190 190 00:08:55,653 --> 00:08:59,460 a single wait is only about consuming premises. 191 191 00:08:59,460 --> 00:09:03,423 The way that we built them is not influenced in any way. 192 192 00:09:04,990 --> 00:09:06,080 Now, right? 193 193 00:09:06,080 --> 00:09:08,983 So this year is going to work the exact same way. 194 194 00:09:12,200 --> 00:09:14,523 And so let's do that here before. 195 195 00:09:18,030 --> 00:09:19,840 And so get positioned, 196 196 00:09:19,840 --> 00:09:22,420 remember it doesn't need any arguments. 197 197 00:09:22,420 --> 00:09:24,190 And so, as you know, 198 198 00:09:24,190 --> 00:09:27,720 all we have to do is to now await this and then store the 199 199 00:09:27,720 --> 00:09:28,700 result 200 200 00:09:28,700 --> 00:09:30,013 into a variable. 201 201 00:09:30,900 --> 00:09:34,263 And just like before let's simply destructor this. 202 202 00:09:36,190 --> 00:09:39,842 And in fact, let me get the code from before. 203 203 00:09:39,842 --> 00:09:42,123 So we don't have to repeat everything. 204 204 00:09:43,070 --> 00:09:45,620 So that was this code 205 205 00:09:45,620 --> 00:09:47,120 and we also need 206 206 00:09:47,120 --> 00:09:49,380 the reverse geo coding. 207 207 00:09:49,380 --> 00:09:51,020 Right? 208 208 00:09:51,020 --> 00:09:54,023 So let's paste all of that here. 209 209 00:09:57,570 --> 00:10:02,250 So what we want here is to get the latitude and longitude 210 210 00:10:02,250 --> 00:10:03,553 from position dot Codes. 211 211 00:10:05,810 --> 00:10:09,180 So probably we should just call this zero first, 212 212 00:10:09,180 --> 00:10:10,103 the position, 213 213 00:10:11,150 --> 00:10:13,400 and then from position dot coordinates, 214 214 00:10:13,400 --> 00:10:18,250 we get the lat and longitude just like before. 215 215 00:10:18,250 --> 00:10:20,730 And then now the next one. 216 216 00:10:20,730 --> 00:10:24,400 So now we can use these latitude and longitude and one more 217 217 00:10:24,400 --> 00:10:28,680 time plucked then into this reverse geo coding 218 218 00:10:28,680 --> 00:10:29,790 API. 219 219 00:10:29,790 --> 00:10:30,830 And so now again, 220 220 00:10:30,830 --> 00:10:35,070 it becomes a lot easier to basically chain premises 221 221 00:10:35,070 --> 00:10:37,350 because we don't have to return anything. 222 222 00:10:37,350 --> 00:10:40,170 We don't have to create new then methods and 223 223 00:10:40,170 --> 00:10:43,130 we don't have to create new callback functions. 224 224 00:10:43,130 --> 00:10:46,380 So all we have to do is to await this 225 225 00:10:46,380 --> 00:10:47,213 and 226 226 00:10:47,213 --> 00:10:48,460 store the results 227 227 00:10:49,310 --> 00:10:51,540 into some variable. 228 228 00:10:51,540 --> 00:10:53,070 So res for 229 229 00:10:53,070 --> 00:10:54,970 a response, 230 230 00:10:54,970 --> 00:10:56,240 but we already have that. 231 231 00:10:56,240 --> 00:10:59,523 So that's call it geo for geo coding. 232 232 00:11:01,728 --> 00:11:04,800 And so let's take a look at that 233 233 00:11:04,800 --> 00:11:06,170 or actually 234 234 00:11:06,170 --> 00:11:07,070 not yet, 235 235 00:11:07,070 --> 00:11:09,370 because we remember that this is going to be 236 236 00:11:10,640 --> 00:11:11,670 just a response. 237 237 00:11:11,670 --> 00:11:13,880 And so we need to get the Jason from there 238 238 00:11:15,780 --> 00:11:16,950 and yet another 239 239 00:11:16,950 --> 00:11:17,783 premise, 240 240 00:11:18,940 --> 00:11:22,480 but this is now so easy and so beautiful 241 241 00:11:22,480 --> 00:11:23,403 to handle. 242 242 00:11:25,610 --> 00:11:26,443 So again, 243 243 00:11:26,443 --> 00:11:27,276 data geo 244 244 00:11:28,280 --> 00:11:30,540 let's give it a safe just to format it a little 245 245 00:11:30,540 --> 00:11:31,820 bit. 246 246 00:11:31,820 --> 00:11:33,520 And I will add some comments here. 247 247 00:11:35,950 --> 00:11:37,400 So geolocation 248 248 00:11:38,340 --> 00:11:39,173 then 249 249 00:11:39,173 --> 00:11:40,590 reverse 250 250 00:11:40,590 --> 00:11:41,560 geo 251 251 00:11:41,560 --> 00:11:42,393 coding 252 252 00:11:44,670 --> 00:11:45,503 and then 253 253 00:11:46,730 --> 00:11:47,773 country data. 254 254 00:11:50,370 --> 00:11:52,200 So just to make sure that it worked, 255 255 00:11:52,200 --> 00:11:54,410 let's take a look at 256 256 00:11:54,410 --> 00:11:55,430 data geo 257 257 00:11:57,930 --> 00:11:58,763 and 258 258 00:11:58,763 --> 00:11:59,596 yes, 259 259 00:11:59,596 --> 00:12:00,553 this is it, 260 260 00:12:02,050 --> 00:12:03,040 right? 261 261 00:12:03,040 --> 00:12:07,610 And so again, here at the country property, we got Portugal. 262 262 00:12:07,610 --> 00:12:10,230 And so now we can plug that into 263 263 00:12:10,230 --> 00:12:11,303 this URL. 264 264 00:12:12,320 --> 00:12:13,810 So that's going to be data 265 265 00:12:13,810 --> 00:12:15,010 geo 266 266 00:12:15,010 --> 00:12:17,000 dot country. 267 267 00:12:17,000 --> 00:12:20,280 And so now we can eliminate the country from here 268 268 00:12:21,880 --> 00:12:24,403 and we also don't need to pass it in anymore. 269 269 00:12:25,300 --> 00:12:26,440 And so, 270 270 00:12:26,440 --> 00:12:27,960 let's reload 271 271 00:12:27,960 --> 00:12:30,230 and we still get the same data 272 272 00:12:30,230 --> 00:12:34,520 about Portugal because that is simply where I am right now 273 273 00:12:34,520 --> 00:12:35,840 located. 274 274 00:12:35,840 --> 00:12:37,870 But in case you're somewhere else, then, 275 275 00:12:37,870 --> 00:12:41,023 you will now get the data about your own country. 276 276 00:12:41,890 --> 00:12:45,760 So let's just take a minute and appreciate how beautiful 277 277 00:12:45,760 --> 00:12:47,253 this data flow here is. 278 278 00:12:48,190 --> 00:12:51,210 Let me just put this comment out here. 279 279 00:12:51,210 --> 00:12:54,570 So we don't clutter or a sync function. 280 280 00:12:54,570 --> 00:12:55,920 Okay. 281 281 00:12:55,920 --> 00:13:00,890 And so we now have all of this in one nice a sync function 282 282 00:13:00,890 --> 00:13:04,410 that runs behind the scenes until everything here is 283 283 00:13:04,410 --> 00:13:06,050 finished. 284 284 00:13:06,050 --> 00:13:09,320 So we are awaiting here one, two, three, four, 285 285 00:13:09,320 --> 00:13:11,130 five premises 286 286 00:13:11,130 --> 00:13:12,850 in a very easy way. 287 287 00:13:12,850 --> 00:13:16,400 And code that now actually looks and feels like normal 288 288 00:13:16,400 --> 00:13:18,050 synchronous code. 289 289 00:13:18,050 --> 00:13:19,960 So to me personally, 290 290 00:13:19,960 --> 00:13:23,270 this a sync await feature was really a huge, 291 291 00:13:23,270 --> 00:13:26,620 huge addition to the JavaScript language. 292 292 00:13:26,620 --> 00:13:27,630 Now, again, 293 293 00:13:27,630 --> 00:13:32,160 just keep in mind that a sync await is just synthetic sugar 294 294 00:13:32,160 --> 00:13:34,420 over consuming premises. 295 295 00:13:34,420 --> 00:13:37,430 So it's a bit like classes in JavaScript, 296 296 00:13:37,430 --> 00:13:40,760 which also hides the true nature of how things work behind 297 297 00:13:40,760 --> 00:13:42,590 the scenes. 298 298 00:13:42,590 --> 00:13:45,240 But I think that's no problem. 299 299 00:13:45,240 --> 00:13:48,660 At least if you already know exactly how premises 300 300 00:13:48,660 --> 00:13:51,670 and asynchronous JavaScript actually do work 301 301 00:13:51,670 --> 00:13:53,270 behind the scenes. 302 302 00:13:53,270 --> 00:13:55,740 And we spent a lot of time in this section 303 303 00:13:55,740 --> 00:13:57,060 learning all that. 304 304 00:13:57,060 --> 00:13:59,453 And so I'm sure that you will be fine. 305 305 00:14:00,360 --> 00:14:04,800 Also a sync await is actually used a lot together with the 306 306 00:14:04,800 --> 00:14:08,450 more traditional then method of consuming premises 307 307 00:14:08,450 --> 00:14:10,433 as we will see in the next video. 308 308 00:14:11,290 --> 00:14:13,950 Now, let me just tell you something, 309 309 00:14:13,950 --> 00:14:17,220 which is when we reload too fast here, 310 310 00:14:17,220 --> 00:14:21,880 then we should get that same error as before from the 311 311 00:14:21,880 --> 00:14:24,770 reverse geo coding where we can only do 312 312 00:14:26,710 --> 00:14:29,183 three requests per second or something like that. 313 313 00:14:31,490 --> 00:14:33,963 Well, I guess I'm not fast enough here. 314 314 00:14:37,250 --> 00:14:38,280 Ah, okay. 315 315 00:14:38,280 --> 00:14:39,163 But here we go. 316 316 00:14:40,660 --> 00:14:43,550 So here we have to at four or three error. 317 317 00:14:43,550 --> 00:14:48,550 And so with this error, our whole example here falls apart. 318 318 00:14:48,660 --> 00:14:53,020 So we get this cascade of errors here and nothing works 319 319 00:14:53,020 --> 00:14:54,210 anymore. 320 320 00:14:54,210 --> 00:14:57,970 And the reason for all of these errors here is because right 321 321 00:14:57,970 --> 00:15:01,650 now we actually don't have any error handling here. 322 322 00:15:01,650 --> 00:15:04,163 And so let's fix that in the next video. 25808

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.