Transcript from the "Async Functions" Lesson
>> Okay, so back to our data fetching, which is what we were trying to do. And why we needed to learn destructuring. Let's destructure the data that we fetched so that we can use it. So let's recap what we did to fetch our [INAUDIBLE]. We had this resource it has a message property, that's what we care about.
[00:00:20] We had done a fetch on this resource URL. And we had captured its value as a response, right? Like this, [LAUGH] with a weight trick question, nice. Okay, then we had parsed out its body as json and captured as the body variable.
>> Await response?
>> Await response.
[00:00:49] And what was the method we used? .json.
>> .json. Okay, so now, all we care about is this array that's inside of this body object, our message property inside of that body object. So what we can do now is extract that. Now we know how with our destructuring, to just pull out the message which in this case is an array of hounds that we care about, great.
[00:01:18] So, what we're gonna do now is basically we have a process or we could call it like a procedure for fetching a resource from a URL. Parsing the response body as json and extracting the message value from within that body. What we're gonna do is take all of that and wrap it up in a function.
[00:01:43] Now, the thing is, if we try and do that in a regular function, we're gonna have a bad time. So here, I've got a function that's it's just the first part of this but just for brevity. We're gonna try to fetch the response from a particular URL and do the same stuff that we did before.
>> Our friend the promise we ring it's beautiful little head again. [LAUGH] Yes, so because this is an asynchronous operation or at least it might be.
[00:03:52] Async functions are going to be promisy. And so that means in order to get the output value of the a sync function, and guess what keyword would I need to use? Wait. Now we have our response, okay? So, this is what we have to do if we wanna use async operations is we need to wrap them in an async function.
[00:04:17] And then that function itself is an async operation, once we introduce asyncyness. Everything else that we're dealing with it, in has to be async.