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
3 answers

JavaScript: differences between async error handling with async/await and then/catch

Just wanted to preemptively say that I am familiar with async/await and promises in JavaScript so no need to link me to some MDN pages for that. I have a function to fetch user details and display it on the UI. async function someHttpCall() { …
Joji
  • 4,703
  • 7
  • 41
  • 86
1
vote
1 answer

executing code inside setTimeout in a asynchronous function?

A simple script, what I am trying to achieve is pushing new item in the append method, and using asynchronous functions I'm trying to understand how then and catch works instead of using them without understanding how they work inside ( using axios…
TaouBen
  • 1,165
  • 1
  • 15
  • 41
1
vote
2 answers

Reusing an existing Promise object if exists

I have a Dialog object that will show, well, dialogs. There are many entry points to show dialogs, e.g. yesNo(), message(), confirm(), etc. However, all these methods basically call the same other method, called showSimpleDialog(title, message,…
velis
  • 8,747
  • 4
  • 44
  • 64
1
vote
1 answer

How can i get value from promise array?

I have a code which has an array of Promises async function getResult(){ ... //resultPromise ==> it has promise in array Ex.[Promise { }, Promise { }] let finalResult = await resultPromise.map((result) => { //result…
1
vote
2 answers

call Async function inside setTimeout

I am working on a project which is built using express and node js. I just need to call the async function inside the SetTimeout function (callback) Here is my Controller File module.exports.create = async (req, res) => { try { // Some DB…
1
vote
1 answer

How to do find all or get all in dynamo db in NodeJS

I want to get all the data from a table in Dynamo DB in nodejs, this is my code const READ = async (payload) => { const params = { TableName: payload.TableName, }; let scanResults = []; let items; do { items = await…
Saurabh
  • 1,592
  • 2
  • 14
  • 30
1
vote
3 answers

Nested function & Promise chaining with error handling trouble - how can I get this to work?

I have learned promise chaining with error handling to my satisfaction as per below first code section. But I am unable to get the following principle working with my Parse Cloud Code. My Cloud code works well but I have monster functions I need to…
RobbB
  • 1,214
  • 11
  • 39
1
vote
1 answer

Can I use Promise.prototype.catch inside async functions that is using await?

Are there any implications of using Promise.prototype.catch inside of async functions where await is used? For example: async funciton sendMessage(topic, bodyObj) { // implementation is not important } async function removeFromInventory(item,…
Dmitry Shvetsov
  • 651
  • 10
  • 19
1
vote
1 answer

How to wait for the response of an OData service's read operation in SAPUI5 before further execution of code?

I have a function (say function1), which midway calls an OData call in another function (say function2). I have some process after the OData call in function1, which is dependent upon the response of the OData read call in function2. Currently,…
d33a
  • 690
  • 1
  • 14
  • 39
1
vote
1 answer

ES6 Promises strangely extract correct value out of custom js objects

I've written a library that is completely separate from Promise API but achieves similar goals. It uses window.requestAnimationFrame and falls back to setTimeout and has nothing common with Promises. In fact you can run it on ie9 - 10 or a machine…
ibrahim tanyalcin
  • 5,643
  • 3
  • 16
  • 22
1
vote
0 answers

Issue when a Proxy object is being resolved as a Promise

As background, I have an async function that does some logic, and eventually (if the browser supports it) returns a Proxy object. This is to support older legacy code that expected an object which can have many different available functions,…
codefactor
  • 1,616
  • 2
  • 18
  • 41
1
vote
3 answers

Promises with ES6 destructuring fails when one of the promises don't succeed

There are a tons of topics about it but I couldn't find this case. Let me explain: const [call1, call2, call3] = await Promise.all([promise1, promise2, promise3]); If they succeed it should return allright, yes? But what if it fails? It throws me…
Ozan Mudul
  • 750
  • 1
  • 9
  • 20
1
vote
1 answer

In WebdriverIO, why does the `expect` line require an `await` in front of it to correctly test something?

This is a somewhat advanced question about WebdriverIO and ES6 JavaScript promises: I just followed the instructions on WebdriverIO to create the project: npx wdio TryWDIO cd TryWDIO and then I modified the test file: //…
Stefanie Gauss
  • 425
  • 3
  • 9
1
vote
3 answers

Promise is not working in Cron Job in NodeJS

Promise is not working inside cronjob in nodejs. let me explain my question with this code. I have one cron that running in every five seconds. Now Inside a cron I have one function client.statistics and I think it's take some time. so I need to…
1
vote
2 answers

Using async function, await and resolve in React component

I have a component with the following structure: const _dbCall = () => { const fooDb = SQLite.openDatabase(db); return new Promise(resolve => { fooDb.transaction(tx => { tx.executeSql(`SOME SQL`, [], (tx, results) => { …
four-eyes
  • 10,740
  • 29
  • 111
  • 220
1 2 3
99
100