14
Codazed
6y

When it feels impossible to get your javascript callback to happen at the right time, so you just throw the callback somewhere just so it works, but you know that it's not the ideal spot for it... 😡😡😡

🖕💻

Comments
  • 6
    Promise you will resolve this someday, and not reject JavaScript's beautiful asynchronous nature!
  • 1
    @balte
    Node.js using Promises on all core modules out of the box. That's a heck of a dream.

    But I certainly hope that we get to resolve that promise. Every JS developer should know about the wonders of the mother of all frameworks that is not a callback hell.

    Promises and async / await (if you prefer).
  • 0
    And don't throw exceptions in callbacks, then effectively assume success and carry on in the main body.
  • 1
    Just use promises, await and async. If it wasn't clear from the other comments.
  • 2
    Specifically, this is the callback I'm having an issue with. I know that this is a horrible spot to put it, but it's the only place I could figure out where to put it that it would work. If it's not inside that for loop, it'll execute before the for loop finishes. Any ideas?
  • 0
    @BaconatorNoVeg The callback will need to be inside of getPlaylistVideos, but doesn't have to be inside the for loop. Define it just before the for loop and give it a name. Then pass the function to getSongData by name.

    cb is getting called multiple times either way, however. This is normally a bad thing. I'd do something with the 'async' library, personally.
Add Comment