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 return same value in then and catch

In JS, let's say I call a promise in a 'fire and forget' way. I don't care if it was successful or not, and I don't care what it returns as I want to return the same value anyways. I can call return myPromise().then(() => foo).catch(() => foo); Is…
Ricola
  • 2,621
  • 12
  • 22
1
vote
1 answer

Why non async function is running asynchronously?

I have a function that must validate some artist from Spotify API, but when I run it artists[] remains empty because the function is running asynchronously, it fills the variable user without having set artists. let artists = [] function…
Giackkk
  • 41
  • 6
1
vote
1 answer

How to wait FileReader.onload loads file successfully?

what I want to do is just simply read multiple file information through for loop. However, Javascript does not wait for the FileReader.onload even if I used Promise. How can we wait for the FileReader.onload ? Here is the code example. const…
S. Yong
  • 79
  • 1
  • 5
1
vote
1 answer

How does error handling work for async map inside an async function?

I have successfully created a function that creates folders according to a directory. However, when I have tried to convert the for of into a map() method using Promise.all(), the error was not handled the same. import { readdir, mkdir } from…
user19471776
1
vote
2 answers

How to tell if a script is done loading?

I have a function which at some time does document.getElementsByTagName("script") and it wants to know for each script if it was loaded already. I'd like to get a Promise which is fulfilled if it was loaded and pending if it's still going on, so I…
Gunther Schadow
  • 1,490
  • 13
  • 22
1
vote
0 answers

In Node.js ES6 how to import and run module in one line?

Running into an issue with converting to ES6 import I haven't found a solution from searches but traditionally I was able to create a Promise as: Promise.all([ require('../path/to/a')('foo'), require('../path/to/b')('bar'), ]) .then(() => { …
DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127
1
vote
0 answers

Dynamic table of Input fields is only giving first input

I have created a dynamic table using JS. Each cell of table contains input fields. I am performing arithmetic operations on input fields. The code is working fine for first input field. But whenever i try to access 2 and further input fields it…
1
vote
1 answer

NextJS getServerSideProps() fetch multiple endpoints at once in delay

Is there a way to fetch data from multiple API routes in a single getServerSideProps() in delay? I encountered an 429 error(too many requests) when I was trying to fetch data from multiple endpoints at once with Promise.all(). Is there any method…
1
vote
0 answers

send multiple ajax post requests at regular intervals until any one of them passed

I am writing a test program for website most of time the website gives 504 error. i want to write a program that can sent ajax requests to server and replace page with server response html. the process of requests is like : send 20 requests at a…
1
vote
1 answer

FetchAPI parallel API calls, making URL array with for loop doesn't work, manual array works. Can't understand why

I'm trying to form an url array to then perform parallel fetches usign .map and Promise.all The code in itself works if I try it with a manually made array but not if I try to form an array (for pagination) with a for loop. I get the maxnumber of…
vazcooo1
  • 181
  • 11
1
vote
0 answers

How to solve error for fetch() call in JS 'Uncaught (in promise) SyntaxError: Unexpected end of input'?

I am working on a promise function and was fetching a API using fetch(). const p1 = Promise.resolve('Hello World'); const p2 = 10; const p3 = new Promise((resolve,reject) => { setTimeout(resolve,2000,'Goodbye'); }); const p4 =…
Papa Bravo
  • 31
  • 7
1
vote
1 answer

React-Query Async Await firing in wrong order loop

I'm batching mutation requests and firing them off with Promise.all however the callback will sometimes trigger before the mutation has. I can only recreate the issue when deleting single items. I know there's some gotchas when doing async/await…
itsclarke
  • 8,622
  • 6
  • 33
  • 50
1
vote
0 answers

How to fix 'Assertion occurred after test had finished' with Qunit

I have a function for an animation that uses a callback. The function uses promises: export function createExpandCollapseCallback( containerSelector, toExpandCollapseSelector, animationDuration ) { return function () { if (…
krickht
  • 29
  • 5
1
vote
1 answer

Asynchronous call stack execution gap

I am reading "Eloquent JavaScript" and at the end of Asynchronous chapter there is a section about execution gap in asynchronous operations and it shows an example. The example code below from the book is not runable as it uses some made up…
dragonfly02
  • 3,403
  • 32
  • 55
1
vote
1 answer

Get all files within a folder containing string, push filenames to array and return array using Node FS

As the title describes, I would like to read all files from a specific directory and return the names of all the files that have a specific string in its contents. Here is how my code looks so far: const dirname =…
user15575918
  • 132
  • 10