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 trialSamuel Kleos
Front End Web Development Techdegree Student 13,674 PointsSmall Qualm. . . ππ½ Where is my ticket number!? π€
In the previous "What is a Promise" video. Guil talks about the coffee analogy. I really focused on this analogy because I got a lot out of it! It's great.
However, he mentions that with promises you get a ticket number but with callbacks you don't.
In the second scenario with promises, you go to the breakfast place, put in your order and pay for it.2:12
The cashier then hands you something back in return, 1. a receipt with an order number and 2. a pager that buzzes to let you know that your order is ready.2:17
At that point, you may go off and2:21 do other things while you wait, like grab a coffee next door or catch up on email.2:22
You're still waiting for the pager to buzz.2:27
But by just having the pager in hand, you now have more control over whether or2:29 not you will have breakfast.2:34
The pager represents a promise that something is going to happen as a result2:35 of ordering breakfast.2:40
With that being said, the promise is pending because you're waiting, so2:42
My question is: What is the ticket number? Is it the promise object with pending object we see below?
All I can see upon running the below code is Promise { pending }
const myPromise = new Promise( resolve, reject) => {
})
console.log(myPromise);
1 Answer
Steven Parker
231,271 PointsIn the breakfast place analogy, the ticket (and ticket number) and the pager are all part of the promise object, they don't represent separate concepts and the ticket and number are not important to the analogy.
There is no separate "pending object", the promise object itself can have 3 states and one of them is "pending". Promises are typically in the "pending" state when they are first created. The code inside the promise must call either resolve or reject to change the state. In the sample above where the promise code block is empty, the state will never change and will remain "pending".
Samuel Kleos
Front End Web Development Techdegree Student 13,674 PointsSamuel Kleos
Front End Web Development Techdegree Student 13,674 PointsThanks for clarifying. In the console it looks like a new object, and in other places the terminology is βthe promise returns a response objectβ so I got confused.