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

Why can't I single-line object properties from objects returned from async functions?

I am wanting to use an object that is returned from an asynchronous function. async function myPromise() { console.log("Single-line", await getUsers().quote); let users = await getUsers(); console.log("Multi-line", users.quote); } async…
Liam Pillay
  • 592
  • 1
  • 4
  • 19
1
vote
1 answer

Promise not resolving even with status of fulfilled and target data on PromiseResult

I need help on this issue I'm experiencing (I have already searched Stack overflow extensively but could not solve it on my own). I have the following "dummy" logic to test async/await behaviour: const data = [1, 2, 3] async function newData() { …
1
vote
3 answers

how to return promise from an async code block

I want to send an http request and return the result using typescript, before send the http request, I want to get the token from google chrome local storage and put the token into http header. This is my typescript code looks…
spark
  • 663
  • 1
  • 5
  • 18
1
vote
3 answers

Does "return await" makes any difference?

Is there any difference between const foo = async () => { // some other code that uses await return await bar() } and const foo = async () => { // some other code that uses await return bar() } Where bar is a function that returns a…
Vencovsky
  • 28,550
  • 17
  • 109
  • 176
1
vote
1 answer

I am trying to increase performance of my code and switching from XMLHttpRequest to fetch requests using asynchronous code

I want to confirm if I am not slowing down the code below. My goal is to increase the performance of the application. I was considering a promise.all but not sure if it is necessary as I believe the code is written now, all the fetch requests are…
1
vote
2 answers

promise catch: how to know if the error comes from promise rejection or from the then statement

Imagine a function that returns a promise (for example fetch from fetch API): fetch(...) .then((response) => {...}) .catch((error) => {...}); How can I know if the error inside the catch statement has been originated due to a promise rejection…
Héctor
  • 399
  • 3
  • 16
1
vote
1 answer

Having trouble returning a promise and then consuming it after a database call

Im learning Javascript and im up to a section on Promises. So decided to try and convert some of my earlier projects to use Promises. But I cant get my head around it. Iv read a lot of guides and browsed through this site but I still cant understand…
AlecJeay
  • 35
  • 4
1
vote
1 answer

how to get [chrome.instanceID.getID] , [chrome.storage.sync.get] by async & await?

How do you get the information for the Chrome extension by using async and await? [chrome.instanceID.getID] [chrome.storage.sync.get] We tried this code: async function test() { let _r = await chrome.instanceID.getID(); return _r; } let _pc_id =…
1
vote
2 answers

How to set order of functions execution inside useEffect hook

I need the useProductList function to execute and finish all process before randomProduct function will execute. For some reason it doesnt work when fetchData is a Promise so randomProduct wont be executed. I even tried without Promise, nothing…
Elassoa
  • 133
  • 2
  • 18
1
vote
0 answers

different result between await async and using .then in javascript

I confuse why I get different result when try to unit test a case using await async and .then in javascript so here it is my await code it.only('should successfully return property data based on userRef', async() => { const result = await…
bramasta vikana
  • 274
  • 1
  • 12
1
vote
1 answer

How to get the output in the same order as the function available in the array in JavaScript

Only change the ABC function, how can I get the output in the same order as the function present in the D variable. I have tried using async-await but getting the output as ['123', 'ankit', '345'] because of the timeout event. const A = (dev) =>…
Ankit Kumar Gupta
  • 1,256
  • 1
  • 10
  • 23
1
vote
2 answers

React: async/await function returns undefined then value I want

I have this async function: Which returns undefined on the first render and then the data from the fetch: const [ MessageListDataProvider, useMessageListData ] = constate(() => { const [messagePath, useMessagePath] =…
1
vote
1 answer

React jsonserver promise result issue

I am creating a react/ redux app with json fake api server I am trying to add a login and trying to get data from json fake api server, data is showing and all ok , but data is always resulting as a promise and the required data is inside the…
famo
  • 160
  • 1
  • 13
1
vote
1 answer

How to implement BluebirdJS synchronous inspection extending a native Promise

I'm updating some old code (not mine originally) that uses Bluebird promises. I'd rather use native ES6 Promises instead, but the old code uses a function Promise doesn't have, one to check if promises have been settled. This is related to a similar…
kshetline
  • 12,547
  • 4
  • 37
  • 73
1
vote
1 answer

Getting a value after promise resolved

I'm trying to understand Promises as best as I can. I was wondering if there's a way of returning the data after the promise had been resolved without chaining as much as I have Basically i was trying to push a new location into the locs…
NewbieAeg
  • 557
  • 3
  • 8
  • 15
1 2 3
99
100