While loop with promises

What would be the idiomatic way to do something like a while loop with promises. So: do something if the condition still stands do it again repeat then do something else. dosomething.then(possilblydomoresomethings).then(finish) I’ve done it this way I was wondering if there were any better/more idomatic ways? var q = require(‘q’); var index = 1; … Read more

How to Check Whether an Angular $q promise Is Resolved

I understand that typically one would just attach continuation code with a then() call and chain behaviour when using promises. However, I want to kick off a promise-wrapped asynchronous call and then separately kick off a 3-second $timeout() so I can take a UI action, ONLY IF the original promise has not yet completed. (I … Read more

return value after a promise [duplicate]

This question already has answers here: setting a variable to get return from call back function using promise (2 answers) How to return value from an asynchronous callback function? [duplicate] (3 answers) Closed 7 years ago. I have a javascript function where I want to return the value that I get after the return method. … Read more

How does Angular $q.when work?

Can some one explain me how does $q.when work in AngularJS? I’m trying to analyse how $http work and found this: var promise = $q.when(config); And here is config object from Chrome console: Object {transformRequest: Array[1], transformResponse: Array[1], cache: Object, method: “GET”, url: “/schedule/month_index.html”…} cache: Object headers: Object method: “GET” transformRequest: Array[1] transformResponse: Array[1] url: … Read more

How do you properly return multiple values from a Promise?

I’ve recently run into a certain situation a couple of times, which I didn’t know how to solve properly. Assume the following code: somethingAsync() .then( afterSomething ) .then( afterSomethingElse ) function afterSomething( amazingData ) { return processAsync( amazingData ); } function afterSomethingElse( processedData ) { } Now a situation might arise where I would want … Read more

Why is ‘this’ undefined inside class method when using promises? [duplicate]

This question already has answers here: setTimeout and “this” in JavaScript (5 answers) Closed 6 years ago. I have a javascript class, and each method returns a Q promise. I want to know why this is undefined in method2 and method3. Is there a more correct way to write this code? function MyClass(opts){ this.options = … Read more

How to get the current taxonomy term ID (not the slug) in WordPress?

I’ve created a taxonomy.php page in my WordPress theme folder. I would like to get the current term id for a function. How can I get this? get_query_var(‘taxonomy’) only returns the term slug, I want the ID Answer Nevermind! I found it 🙂 get_queried_object()->term_id; AttributionSource : Link , Question Author : InvalidSyntax , Answer Author … Read more

Are there still reasons to use promise libraries like Q or BlueBird now that we have ES6 promises? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago. Improve this question After Node.js added native support for promises, are there still reasons to use libraries like Q … Read more