EDIT: I could not figured out how my code is different from the link you provided and the blog, is that possible to pinpoint what/where i'm doing wrong? I'm trying to wrap my head around with promises and I have multiple serverside calls here is what I'm trying to figure out:  Only executes the second server call if the FOUND is true, for the sake of testing I have hard-coded the boolean value but in the real scenario I will be reading from server side.  Why I'm doing the conditional call? I don't want to hit the server if the first call returns false. Here is what I have done so far: Apex: public class PromiseTestController {     @AuraEnabled     public static String serverSideCall1(String message ){         return ' From Server serverSideCall1--&gt;' +message ;     }     @AuraEnabled     public static String serverSideCall2(String message ){         return ' From Server serverSideCall2--&gt;' +message ;     }       }  Component: &lt;aura:component controller=&quot;PromiseTestController &quot;&gt;          &lt;aura:attribute name=&quot;serverSideCall1&quot; type=&quot;String&quot;  default=&quot;Not started&quot; /&gt;     &lt;aura:attribute name=&quot;serverSideCall2&quot; type=&quot;String&quot;  default=&quot;Not started&quot; /&gt;      &lt;ui:button label=&quot;PromiseChaining &quot; press=&quot;{!c.promiseChaining}&quot; /&gt;           &lt;div&gt;         {!v.serverSideCall1}     &lt;/div&gt;         &lt;div&gt;         {!v.serverSideCall2}     &lt;/div&gt;       &lt;/aura:component&gt;  Controller: ({           promiseChaining : function(component, event, helper) {          var found = false; //TESTING         var exeAction = component.get(&quot;c.serverSideCall1&quot;);         exeAction.setParams( {&quot;message&quot;: 'Promise serverSideCall1'});         helper.serverSideCall(component,exeAction).then(             function(res) {                   component.set(&quot;v.serverSideCall1&quot; ,res ) ; //RETURN FROM SERVER...serverSideCall1                 if (found) {                   var exeAction2 = component.get(&quot;c.serverSideCall2&quot;);                   exeAction2.setParams( {&quot;message&quot;: 'Promise serverSideCall2});                   helper.serverSideCall(component,exeAction2).then (function (res) {;                    component.set(&quot;v.serverSideCall2&quot; ,res ) ; //RETURN FRO SERVER serverSideCall2                 })                              }          .catch(             function(error) {                 component.set(&quot;v.status&quot; ,error ) ;                  console.log(error);             }         );     },           })  Helper: ({     serverSideCall : function(component,action) {         return new Promise(function(resolve, reject) {              action.setCallback(this,                                 function(response) {                                    var state = response.getState();                                    if (state === &quot;SUCCESS&quot;) {                                        resolve(response.getReturnValue());                                    } else {                                        reject(new Error(response.getError()));                                    }                                });              $A.enqueueAction(action);         });     },         })
When I read about , I see that they should appear as solution to prevent  and  but when I actually try to write a code which would use Lightning promises it still doesn't look like synchronous code, it still resembles both pyramid of doom and callback hell.  main: function(component, helper) {     helper.promise1(component, helper).then(         $A.getCallback(function(record) {             return helper.promise2(component, helper, record).then(                 $A.getCallback(function(){                     console.log("Success");                     helper.showToastMessage(component, "Great Success!!!!")                 }),                  $A.getCallback(function(errorMessage){                     console.log("Rejected by second promise2");                     helper.showToastMessage(component, "Failure " + errorMessage);                 })              )         }),          $A.getCallback(function(errors){             console.log("Rejected by first promise1");             let message = errors &amp;&amp; Array.isArray(errors) &amp;&amp; errors.length &gt; 0 ? errors[0].message :'Unknown error';             helper.showToastMessage(component, "Failure " + message);         })      ) }   Is that possible to refactor this code to look more like synchronous code and without callback hell or pyramid of doom?
What does functools.wraps do? Is there any way to get the number of pending chat request on omni channel? I have a requirement to get the number of pending chat request in the omni channel.  I have set the presence configuration capacity to 5 so that an agent can have only 5 chat requests. if a case is solved agent will get one of the pending chat request. But right now i can't see the number of pending request.     Lets say i have 10 pending request in the queue, but i don't have any numbers to see how many are pending in the queue.   Is there any way that can show the pending chat requests in the queue? We built our eCommerce web site using Angular as a single page application.  We have implemented a spinner that runs until the page is responding with the expected content. We have some category pages which were crawled and indexed by Google but which are no longer available on the site. What is the best practice for old pages?  Should I create &quot;404 Not Found&quot; pages for them instead of saying &quot;loading&quot; forever? Is setting a no index meta tag enough? I am writing a small KOMA-Script scrartcl document with multiple sections. In the table of contents, LaTeX fills the current line with dots between the end of the section name and the page number. Is there any way to customize this behavior? I would like to reduce the space between the single dots (i.e. use more dots in the same space). What's the term for using the wrong word because it sounds the same? I was reading about various terms for incorrect words, but they didn't seem to fit.  I saw a post where someone said "what do you like to do when you're board?".  That kind of thing.  Also, would that be considered a mistake in grammar?  I didn't think so, but my friend insists it is.  I'm not sure if there even is a word for that kind of mistake, but was just curious about it.  Thanks! When I try to print a Unicode string in a Windows console, I get an error . UnicodeEncodeError: 'charmap' codec can't encode character .... I assume this is because the Windows console does not accept Unicode-only characters. What's the best way around this? Is there any way I can make Python automatically print a ? instead of failing in this situation? Edit:  I'm using Python 2.5.  Note: @LasseV.Karlsen answer with the checkmark is sort of outdated (from 2008). Please use the solutions/answers/suggestions below with care!!  is more relevant as of today (6 Jan 2016). Does there exist an $a_0$ such that the sequence $a_{n+1} = 2a_n + 1$ is prime for all $n \ge 0$? I believe I see that $a_n = 2^n(a_0+1) - 1$ but am somewhat uncertain where to proceed afterwards. I am a complete beginner at number theory and would appreciate it if someone could point me in the right direction--surely there is some obvious argument I am missing. Vortex in liquid collects particles in center I'm curious whether I can find the overlap $\langle q | p \rangle$ knowing only the following:   $|q\rangle$ is an eigenvector of an operator $Q$ with eigenvalue $q$. $|p\rangle$ is an eigenvector of an operator $P$ with eigenvalue $p$. $Q$ and $P$ are Hermitian. $[Q,P] = i \hbar$.   I'm asking because books and references I've looked in tend to assume that $Q$ is a differential operator when viewed in the $P$-basis, then show that it satisfies the commutation relation. (I haven't read one yet that proves that the form given for $Q$ is the only possible one.) I've heard, though, that we can work purely from the hypothesis of the commutation relation and prove the properties of $Q$ and $P$ from it. I've been informed by those who know much more about Harry Potter than I that Hogwarts is protected with a Disillusionment Charm so all muggles will see is ruins with a "Danger: Keep out!" sign around them.  (Apparently this was in one of the first three books, but I'm not sure where it was.)  My first thought was, "Well, a danger sign would encourage some muggles to investigate!"  Which leads to what I think is an obvious question: Will a disillusionment charm on a place like that still work when a person is real close to the location?  Will it work from inside the location?  For example, if a curious muggle made it to the gates of Hogwarts and started walking around inside, would they still see it as abandon and in ruins, or once they entered, would they see it as it is? Controlling Volume Mixer Why Faces eat each other? Identifying Coordinate System of Shapefile when Unknown? How to declare a variable inside bash -c I can't figure out how to declare a variable inside bash -c command.   bash -c "var=3; echo $var" What are examples where a "naive bootstrap" fails? What is the best term to describe the fact that most users have an initial dislike of any change to a UI even though it may really be net better over time?  Note: Question originally appeared Follow a question I've come across a few interesting questions over the last few months on Stack Overflow. They're not necessarily questions I need an answer to, but the questions are nonetheless very interesting, and now I want to know what the answers are.  I don't want to add this question to my favourites because I have my really handy posts in there.   Ideally I would like to have another kind of shortlist to which I can add these posts. I would get notifications just as if it were my own post, without having these as favourites.  What do you think of that? It would be available only for questions, and you would receive notifications just like the author, for new answers and comments on the question (not comments on the answers).  You could browse the posts you're following, as well as stop following them.   The thing is sometimes I come across a semi interesting question and upvote and maybe even comment, but I never hear about it again, because sometimes it's just not interesting enough to remember.  Like I said in the comments, I don't feel like the favourite list is really for this. I want in-your-face red dot notifications for new answers on brand new interesting questions I find. The favourites is for that post with an answer that you know you'll need again. How to get rid of banding in illustrator while using gradient? How to get Rid of Banding in illustrator while using Gradient Could it be that Goldbach conjecture is undecidable? Currency formatting in Python I am looking to format a number like 188518982.18 to £188,518,982.18 using Python.  How can I do this?