Converting Callback Functions to Promises

Поділитися
Вставка
  • Опубліковано 16 січ 2025

КОМЕНТАРІ • 30

  • @Horse-tradeEu
    @Horse-tradeEu 3 роки тому +13

    This channel is underrated. Has no click bates, fancy previews and the quality of the content is amazing. Thank you Steve!

    • @rmnkot
      @rmnkot 3 роки тому +2

      completely agree!!!

    • @simple8810
      @simple8810 3 роки тому

      true he is gem,I wanna share this channel on social media to support this man,and so that everyone get advantages

  • @sinxenon3181
    @sinxenon3181 Рік тому

    I fell in love with your voice! Also the video is very clean and helpful! Thank you!

  • @gyros9162
    @gyros9162 3 роки тому

    This is just a spectacular channel! He explains complicated stuff in a very succinct and professional manner.

  • @akmalshareef4785
    @akmalshareef4785 2 роки тому

    Thank you for the clear and concise video. This deserves more views

  • @kriscollins1541
    @kriscollins1541 2 роки тому

    This is explained so well, thank you very much

  • @marcscherzer
    @marcscherzer 3 роки тому +9

    Next : convert your promises to async-await

  • @zb2747
    @zb2747 Рік тому

    Love your channel

  • @allezzthepunk
    @allezzthepunk 3 роки тому

    Very useful information

  • @Genocidechaos
    @Genocidechaos 2 роки тому

    Thank you very much. In the then() chaining we could add an optional function for reject correct?

  • @omega.developer
    @omega.developer 3 роки тому

    very nice explaination..

  • @HarshKapadia
    @HarshKapadia 3 роки тому

    Why do you use the 'DOMContentLoaded' event rather than the 'load' event?
    As always, thanks for the video, Steve!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому +3

      Because the DOMContentLoaded event fires after the HTML has been read. The load event waits for the CSS, JavaScript, images, fonts, media, etc. The time delay for the load event can be much greater than DOMContentLoaded.

    • @HarshKapadia
      @HarshKapadia 3 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 aah okay. Thank you!

  • @jabed-web-dev
    @jabed-web-dev 3 роки тому

    Sir, please give a video about Node JS Async Hooks Module.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      Please add any tutorial requests in the comments here - ua-cam.com/video/LCezax2uN3c/v-deo.html. - and vote for others that you like.

  • @rickyu1978
    @rickyu1978 3 роки тому

    passing in resolve in to a setTimeout .. is resolve itself a function? normally i see setTimeout(function() .....
    Also, your catch, you wrote console. error, should it have been console.log(err) ? or perhaps console.error(err) .. Thank you

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 роки тому

      Resolve is a function so it can be passed to the setTimeout as the function to call.
      Console has many methods. Error warn info log and more. The catch method expects a function. So console.error is the function being passed in.

  • @Dr.smileclinic
    @Dr.smileclinic Рік тому

    Can you explain callback to async function

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому

      Callbacks are the same regardless of what kinds of function you are calling. It doesn't matter if they are synchronous or asynchronous. The purpose of a callback function is to be called after the current function is complete. Since they don't return to the current function when they are done it doesn't matter if they are async.
      function start( theCallBackFunc ){
      //do a bunch of things
      //then call the callback when complete
      theCallBackFunc( );
      }

  • @ioannis2000
    @ioannis2000 3 роки тому +1

    The dark forces of callback function brought chaos over the lines of resistance code. Then the Jedi Master Steve Griffith come with Promises and the Light won over darkness

  • @Konstantin19877
    @Konstantin19877 2 роки тому

    good content!

  • @mocococo2877
    @mocococo2877 2 роки тому

    Thank you again and again greetings from Bulgaria.
    Please help me once more Master Griffith to understand something that looks so trivial but yet eludes me. Please explain why you (and many other authors / developers) use anonymous intermediate functions to call the callbacks. Well, your example is a bit different but I hope you understand what I mean in general.
    someAsyncFn(() => { - here those functions I mean
    nextAsyncFn(() => { - here those functions I mean
    ............
    What about using them directly. Like:
    someAsyncFn(
    nextAsyncFn(
    ............
    I have seen examples of those too. So what is the difference ?
    Thank you.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 роки тому

      Using this example from my code:
      delay(delay1)
      .then(() => changeBtnColor()) //return value gets passed to the next then()
      .then((d) => delay(d))
      It could also be written like this:
      delay(delay1)
      .then( changeBtnColor ) //return value gets passed to the next then()
      .then( delay )
      Both do the exact same thing. Normally I would add the extra anonymous function if there were a couple of lines of code to add. In this example, it was just to keep the appearance consistent and it is easier for junior devs to understand.

    • @mocococo2877
      @mocococo2877 2 роки тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Once again the Jedi Master Steve Griffith came to the rescue to one of his students as he was surrounded by dark and DECEIVING forces of JavaScript. For more info where the story began - look for IoannisX down below .
      This one sentence was the key.
      "Normally I would add the extra anonymous function if there were a couple of lines of code to add."
      Thank you.

  • @CastleShield
    @CastleShield 3 роки тому