Questions tagged [es6-promise]

An ES6 Promise is an ECMAScript 2015 object that represents an in-progress asynchronous operation

An ES6 Promise is an ECMAScript 2015 (ES6) object that represents the eventual completion or failure of an asynchronous operation. The ES6 Promise API is based on the Promises/A+ specification.

Consumer-side, a promise is essentially a returned object to attach callbacks to, instead of passing callbacks into a function. The .then function lets callers chain operations to be run subsequently.

In an ideal world, all asynchronous functions would return promises. However, a promise may also be created from scratch using its constructor, to wrap old callback-style function calls.

Promise objects have three possible states:

  • Pending
  • Fulfilled
  • Rejected

Resources

Related Tages

5243 questions
1
vote
1 answer

Nodejs: Responding synchronously to a request by calling an asynchronous service

I'm writing a Nodejs based service, N, that sits between entities A and B. A <----> N <----> B App A POSTs a synchronous request to N, which N must respond to with data it can only get by calling an external service B. The problem is, B is an…
Harry
  • 3,684
  • 6
  • 39
  • 48
1
vote
2 answers

Async Function with Promise.All Only Running After Updating Code

I'm writing an asynchronous function in React that should set the "coords" state to an array of objects containing US states and their respective latitudes/longitudes. To do this, I'm making an API call and resolving those calls using Promise.all.…
1
vote
0 answers

Is it a bad practice to use Promise just to chain the excecution in the proper sequence?

I'm developing an app with a Sign In with Google Firebase. I've got the need to update de current user data wich exists within a Auth Module when a user sign in, and then chain the execution of stuff with that specific data. Something like this…
1
vote
2 answers

How to catch an error on a async callback function on outer try/catch block

Ok, So I am using the puppeteer framework and I have an async function that interact with a webpage. This function clicks and selects and elements of a webpage while it waiting for the traffic of the page to be idle. This function works most of the…
1
vote
1 answer

Is there a way to resolve the inner promise of this rxjs observable?

(concat(ready$,processPlugins$) as Observable<{ plugged: PluggedModule; cmdPluginsRes: { execute: Awaitable>; type: PluginType.Command; name: string; description:…
Jacob Nguyen
  • 25
  • 1
  • 1
  • 4
1
vote
0 answers

Javascript get result of Promise and return in a non async function

There is some library I use and it's function returns a promise. function Something() { return new Promise((r,e) => { r(true); }); } And I have my code: //async function MyFunction() NO! //function MyFunction(callback)…
Man Tachi
  • 11
  • 2
1
vote
2 answers

If condition after result of Promise

I have a problem with a promise. I have this function that is used to comunicate with Firestore database: async getDataFromDB() { const junctionRef = firebase .firestore() .collection('junction') .doc(this.id) …
1
vote
1 answer

JavaScript - Promise parameter

I studying Promise in Javascript. The two examples look similar, but they produce different results. The difference is that each parameter of 'then' is used, but I don't know the exact cause. code #1 const promise = new Promise((resolve, reject) =>…
MOGI
  • 11
  • 2
1
vote
1 answer

Fetching data with Nuxt

I'm calling data with Nuxt async fetch() like this: export default { .... async fetch() { let childrenUrl = process.env.VUE_APP_MGNL_API_PAGES + this.projectPage + "/@nodes"; await this.$http.$get(childrenUrl).then(childResult => { …
skQ
  • 11
  • 5
1
vote
1 answer

Is it possible to translate ANY async-await function to old school .then().catch() when loop is involved

I am trying to convert my async-await function to the old school Promises way. The main challenge is that I need to loop through a function and use the response to fetch more. Here is my function: async function getHierarchyForId(id) { try { …
Yoël Zerbib
  • 177
  • 2
  • 10
1
vote
1 answer

Error: DeprecationWarning: Unhandled promise rejections are deprecated. - Promises in Javascript with Selenium

I am trying to set up some test cases with Selenium in Javascript for a simple login page test. I am at the point where I am trying to set up proper error catching by rejecting within a Promise. Here is my Promise code: //Test Case 1: Valid Email…
1
vote
2 answers

Nodejs with mysql2, promise functions in are not excuted in order

In my nodejs app I need to write data into my mysql database, then create a PDF file out of this data and then send this file as an attachment in an email. The two functions generatePDF() and sendMail() are async function and, therefore, return a…
maraxai
  • 135
  • 1
  • 3
  • 14
1
vote
1 answer

Properly resolving multiple twttr.widgets.createTweet promises

I'm trying to add multiple tweets to a page as it is paginated. However, I cannot seem to get widget.createTweet promises to resolve in order to add their element to the page. Here is the logic from my reduced Codepen example. // increment current…
Ben Racicot
  • 5,332
  • 12
  • 66
  • 130
1
vote
1 answer

Using JavaScript Promise All - is this syntax valid?

I have two tables with users, where each id for one user is same in both tables (don't ask why I have two user tables). At some point, I need to filter users from table 1, and if certain condition is true, I store a promise (deleting request) for…
1
vote
2 answers

Promise.allSettled() - Retry strategy for multiple async calls

TL;DR: I'm looking for a strategy or an example of handling an unknown amount of promise rejections and retrying them an X amount of time when using Promise.allSettled() for multiple async calls. After reading this article:…
Maor Barazani
  • 680
  • 3
  • 12
  • 31