Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjun cheng wong
17,021 PointsHow promises perform asynchronous tasks?
I understand how callback works asynchronously, but I cannot understand how promise does it.
jun cheng wong
17,021 PointsHi, can you provide me an example of how promises not blocking the other code to run?
1 Answer
JASON LEE
17,352 PointsIf you understand how callback works asynchronously, then you can see when declaring a new Promise
, it accepts a parameter which is a callback function. Promise
uses a callback function, and callback function works asynchronously, therefore Promise
works asynchronously.
The callback function is the one that is passed two arguments (resolve and reject).
This is my understanding so someone feel free to correct me if I'm wrong.
EDIT: I am not sure whether or not callback functions by themselves are asynchronous (probably not?), but they are often seen in asynchronous operations due to the ordering in which it's executed. Also now I'm second guessing whether I used the proper terms: parameter vs argument, or vice-versa. Because if you can't distinguish parameter vs argument, esp. when working with callback/higher order functions, it's really easy to get lost. Someone please advise.
Reggie Williams
Treehouse TeacherReggie Williams
Treehouse TeacherHey jun cheng wong promises work like callbacks and differ in syntax. Which part of promises were you unsure about?