Async Generators - Javascript In Depth

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024

ความคิดเห็น • 27

  • @fabioescobar5463
    @fabioescobar5463 ปีที่แล้ว +7

    You are very clear in explaining bro! You anticipated all the mistakes I was going to make LOL

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +1

      Thanks Fabio! Haha, that's good to hear! This is quite a tricky topic so I hope it was useful 😊

    • @shivamgupta3652
      @shivamgupta3652 ปีที่แล้ว +1

      Exactly

  • @tomboolery
    @tomboolery ปีที่แล้ว +3

    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 ✌🏼

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +1

      Hey Tom - Definitely super cool, haha! It's an important and fancy concept that underpins a lot of underlying stuff in JS and even other languages 😊

  • @jjjj5452
    @jjjj5452 3 หลายเดือนก่อน +1

    yeah there was a lot going on here, but you've made it clear, thanks

  • @shivamgupta3652
    @shivamgupta3652 ปีที่แล้ว +3

    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

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +2

      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 TH-cam 😃

    • @shivamgupta3652
      @shivamgupta3652 ปีที่แล้ว +2

      @@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

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +2

      💯 couldn’t agree more!

  • @Kiran-khadka
    @Kiran-khadka ปีที่แล้ว +4

    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👀

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +1

      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 😊

  • @DannyGorelik
    @DannyGorelik ปีที่แล้ว +3

    That's very nice thank you for the explanation :)
    But how can i mock these functions for testing?

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +1

      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 😊

  • @Abulkhair1995
    @Abulkhair1995 ปีที่แล้ว +1

    your chanel grows more I wish...

  • @dsstudios178
    @dsstudios178 ปีที่แล้ว +1

    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...

    • @dsstudios178
      @dsstudios178 ปีที่แล้ว

      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

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว

      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 😊

  • @jeremiahabiola994
    @jeremiahabiola994 ปีที่แล้ว +3

    Nice video man.

    • @jeremiahabiola994
      @jeremiahabiola994 ปีที่แล้ว +2

      Please after this series make a video on api. Json and ajax. They are confusing..

    • @TechWithNader
      @TechWithNader  ปีที่แล้ว +1

      I totally agree and that is the plan! Do you think it would be more helpful to have that first or front-end and react first?

    • @jeremiahabiola994
      @jeremiahabiola994 ปีที่แล้ว

      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 🤧🤧

    • @jeremiahabiola994
      @jeremiahabiola994 ปีที่แล้ว

      @@TechWithNader It depends on your plan.. I feel combining the two might be stressful... Html ,css.. A lot to cover especially in css.

    • @jeremiahabiola994
      @jeremiahabiola994 ปีที่แล้ว +2

      @@TechWithNader I feel you should focus more on the backend

  • @ShivamSharma-dq4pu
    @ShivamSharma-dq4pu 6 หลายเดือนก่อน

    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