Intro to Async and Await

  Рет қаралды 6,574

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

Пікірлер: 31
@عاشقالشارقة
@عاشقالشارقة 5 жыл бұрын
you are brilliant Steve, you make complicated things simple and easy to understand, thank you so much
@Daniel-nb3kk
@Daniel-nb3kk 4 жыл бұрын
Your channel is the first place I go whenever I have some difficulty understanding a concept! :)
@rotrose7531
@rotrose7531 4 жыл бұрын
Most easy to understand async await tutorial I ever learnt. Thank you.
@dinaiswatching
@dinaiswatching 5 жыл бұрын
Great tutorial, Steve. Your videos are simple and intuitive, that's my favorite channel to learn new concepts of Javascript, thanks a lot.
@waneagony
@waneagony 2 жыл бұрын
You are the best at explaining JS things, Steve. Thank you.
@Mirzaves
@Mirzaves 5 жыл бұрын
Great explanation) Smooth and without hard theory. Thank you, Steve!
@blottolotto7648
@blottolotto7648 3 жыл бұрын
nice one! Just watched 2 vids that were crazy deep lol. This was way easier to understand
@usmaness
@usmaness 6 жыл бұрын
your explanation is always simple & ♥
@martinbozinovski
@martinbozinovski 5 жыл бұрын
very nice explanation. You just got a new subscriber. Nice work!
@alicandonmez6748
@alicandonmez6748 5 жыл бұрын
Very simple explanation. Keep up the good job!
@chesterxp508
@chesterxp508 3 жыл бұрын
Another very cool tutorial!
@alokp2003
@alokp2003 4 жыл бұрын
Hi Thanks for the explanation.. Why can't I assign the response of async to a variable.. Let's say I am fetching a JSON object from async and I want to assign it to a variable(outside async func) for future use. Like why do I have to write my code in..then() always.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Using .then( ) is the built-in way of getting the response value. If you want to use async you can get the result that way too. let myVar = await fetch( url ); myVar will contain the response object from the fetch OR the error object.
@alokp2003
@alokp2003 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 i think i didnt frame y question correctly.. var v; let prom = async( some json data ); prom.then( e=> {v = e;}) ...why cant i do this ? i mean not literally in same way but i want to store e (json data) in a variable v for later use..what i see is e is available only in then()
@vipinsharma-zx9cb
@vipinsharma-zx9cb 3 жыл бұрын
can we say that "await" will pause the , only single thread of JavaScript processing. it stops executing! But then I have seen people using this in Node.js as well , will it not hamper the performance?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
The main stack is a single thread. The event loop, (service|web) workers, and async tasks are on another thread. This keeps the performance of the main thread efficient.
@vipinsharma-zx9cb
@vipinsharma-zx9cb 3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 ok, got it.
@ricardodesirat2590
@ricardodesirat2590 2 жыл бұрын
Hi Steve. The returned value is 42 anyway or we have to go to PromiseValue [and how]? Thank you
@mathewi2761
@mathewi2761 6 жыл бұрын
really nice explanation
@vipinsharma-zx9cb
@vipinsharma-zx9cb 3 жыл бұрын
Steve if possible Please make a tutorial on Reactive programming, covering concepts like observables/subscribers / rxjs etc
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Please put requests in the comments here - kzbin.info/www/bejne/gnTIq5SuZ9qBacU or look for the request if it is already there and vote for it.
@natarajannarayanan8277
@natarajannarayanan8277 4 жыл бұрын
Nice explanation... I have one doubt 1) how we can handle the error logic ? i.e data not available or something else
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
If you mean handling errors with fetch( ), then you chain the catch( ) method on the end. It captures all errors with fetch. In general, with await, you can wrap it inside a try { } catch( err ){ } However, since await is wrapping a Promise around your code, it can also use the catch( ) method. I talk about some of this here - kzbin.info/www/bejne/r5StgI2mlNyKl80
@hacker2ish
@hacker2ish 6 жыл бұрын
But why is a simple conversion to JSON an async function?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
The Response / Body objects have a blob( ), text( ), and json( ) method to extract and convert the appropriate format from the result that came back from the server. Since we have no idea how large that response object is, we don't want to block other operations on the page when we do the conversion. Therefore, we get a Promise object which will EVENTUALLY give us the converted data.
@gabrielsroka
@gabrielsroka 5 жыл бұрын
Great video. One minor correction: `response.json()` converts from JSON (not to JSON).
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 жыл бұрын
Yes. Sorry. Misspoke there. It does convert from the JSON string to a JavaScript Object.
@ManontheBroadcast
@ManontheBroadcast 6 жыл бұрын
But in line 26 you use the data variable that you still don't have ... shouldn't there be the await keyword too? ... Thanks in advance and BTW, great tutorials ... straight to the point and comprehensive. Keep on ...
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
It is declared and assigned on line 24. Lines 23 and 24 both have an await. Your understanding is correct.
@Colstonewall
@Colstonewall 6 жыл бұрын
This is one thing that's always confused me somewhat with Asynchronous Operations. . .If Asnc is "non blocking", aren't we doing exactly that using "await"? We're waiting for each of those two lines (23, 24) to finish before moving on (by using await). So, aren;t we blocking doing this Steve? BTW, I get using await is basicly the same as using "then" in a normal Promise. So, my question refers to both Promise and Asnc/Await.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Yes. Await is a way of turning asynchronous code into synchronous code.
Combining Async Await with Promises
9:10
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 8 М.
Intro to JavaScript Symbols
9:46
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 15 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Async JS Crash Course - Callbacks, Promises, Async Await
24:31
Traversy Media
Рет қаралды 1,4 МЛН
Promises in Javascript
10:23
Piyush Garg
Рет қаралды 74 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 497 М.
Understanding the Keyword THIS in JavaScript
13:59
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 9 М.
What are JavaScript PROMISES? 🤞
12:37
Bro Code
Рет қаралды 90 М.
Async Iterators for Big Data Sets
10:58
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 4,1 М.
The Complete Guide to JS Symbols ES6
12:18
Colt Steele
Рет қаралды 55 М.
Asynchronous JavaScript Crash Course
1:28:03
Codevolution
Рет қаралды 215 М.
Real 10x Programmers Are SLOW To Write Code
14:51
Thriving Technologist
Рет қаралды 71 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН