Generators seem ridiculously powerful, with async generators even more so. I can’t wait to progress and see how we’re going to be using them in tandem with APIs (the idea that we can input into .next() to influence yield returns got my mind racing). Thanks again Nader you’re helping so many people ✌🏼
Other youtubers finish these topics in 5 minutes. But your way of teaching is totally different that a student cannot forget the concept. Every person should persue through your course who wants to learn JS
Thanks Shivam! That pretty much sums up my approach to teaching, so I'm glad it's coming across and you're finding it helpful! I was curious to know if people would be ok with such long-form content on RU-vid 😃
@@TechWithNader well everyone who learns programming should know, good things take time, especially programming so i would not mind if they will be more longer
Wow! Your tutorial are great 🖤 Love your content 💓 I wish if you have started earlier so that I should not have to jump between tutorial to know what's actually is happening! Because you cleared all the concepts as possible so that beginner like me felt comfortable with the Concepts relates to topic 🖤 Wow wow wow👀
Thanks Kiran! That means a lot to me 😊 I’m glad you’re learning so much and clearing up concepts you wanted to know more about. Let me know if you have any ideas or feedback for other topics 😊
Theres a weird thing going on. Code similar to what you used: function* foo_gen() { yield new Promise((resolve, reject) => { setTimeout(() => { resolve("Finished!"); }, 3000); }); } for await (const promise of foo_gen()) { console.log(promise); } Gives same error for me in node, but in the browser's console this gives no error and returns "Finished!" after the 3 seconds. Why? We can also replace foo_gen() with a `new Promise()` but it will error if it isnt in a array?? [new Promise()] This feels very strange...
I found somewhat of an answer for people curious. chrome seems to have a `top-level await` that makes this work, its likely node doesnt have this. So this top level await will await any value passed to the for...of loop's variable. This means when we pass a promise: `for await ( const promise of new Promise(...))` we error, as a promise is an Object, not iterable. But if we did: `for await ( const promise of [new Promise(...)])` Its in an iterable array now and now `promise = new Promise(...)` which will be awaited. This works with the generator function for the same reason, when the `for await (const yielded_promise of generator())` runs, like we know by know, the loop will run generator.next() and assign the yield value to the `yielded_promise` variable. So once again we will await this value :D Please note, this seems to not be in node, but in the google console. Also it will technically await ANY value, `await 5;` for example. Someone feel free to correct me, hope im on the right track about this, but for now imma stick to normal node.js
Interesting finds! What was your original error, in Node? Deno which is another newer runtime also has a 'top level await' feature, which can be nice if used correctly haha 😊
Hey Danny! Good question - it really depends on the testing library/framework you're using. It would be similar to testing any other Promise-based functionality. Lots of them allow you to "await" the tests and verify their results before moving on to other non-related tests 😊
I guess the front end. Cause making videos on apis won't be complete without knowing the front end, with the exception of backend devs sha. But it will be a very long series 🤧🤧
30:50 you say that for await (const promise of asyncGeneratorObject) { console.log(promise); } will not work for normal generator but i try to ran at but it ran just fine. const normalGenerator = function* () { let i = 0; while (true) { yield new Promise((resolve, reject) => { setTimeout(() => { resolve(i); i++; }, 1000); }); } }; const normalGeneratorObject = normalGenerator(); const asyncGeneratorExecuter = async () => { for await (const promise of normalGeneratorObject) { console.log(promise); } }; asyncGeneratorExecuter(); this is working fine