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

How to reject child Promise using AbortController

I just learned about how to reject a Promise by using the AbortController API. It's working fine but when the promise to reject as a "child Promise", this one will still continue running even if the parent Promise is rejected. Is there a way, when…
johannchopin
  • 13,720
  • 10
  • 55
  • 101
1
vote
1 answer

How to use a single default catch in a double returned promise?

Basically I have a construction like; // Library function function foo(){ return new Promise((resolve, reject) =>{ // Do lots of stuff, like rendering a prompt // On user action if(userDidSomething){ resolve(user_input); } …
NoobishPro
  • 2,539
  • 1
  • 12
  • 23
1
vote
1 answer

Promises and Axios request still returns 429 despite setTimeout

I've been having a problem with the Reverse Geocode API provided by TomTom where I get 429 responses back, because I am mapping over 72 latitude and longitude objects to the API. So I decided tried to make a function which would wait 5 seconds…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
1
vote
1 answer

Follow on actions after asynch function completion

I'm going to do my best to explain this one since this is a reduced version of the real code and some parts might seem redundant or excessive (and they might be). The model can be found at https://jsfiddle.net/ux5t7ykm/1/. I am using a function to…
Eric Smith
  • 37
  • 5
1
vote
0 answers

Trouble with nested promises, only updating last year in for loop

I am working on an application, using Python and Django for the backend and React for the frontend. I ran into a time complexity issue with a backend post route. I am allowing users to pass in credentials and making API requests to pull a massive…
JF12345
  • 11
  • 3
1
vote
3 answers

Await an array of Promises mapped from Object entries

With the following snippet code the function should await all the promises mapped from the Object entries node. For instance the $eval function comes from the Playwright library and throws an error due to the fact that the target document in which…
1
vote
3 answers

Using JS Promise as an interrupt

I wanted to directly call a function (like interrupt handler) when a certain condition is met. I didn't want to using "polling" for that as it increases time complexity. count = 1 p = new Promise((resolve, reject)=>{ if(count == 2){ …
1
vote
2 answers

Can't get response body in Axios with express

My frontend code: const user = useSelector(selectUser) function getWatchLater(name){ axios.get('http://localhost:5000/watchlater', {user:name}) .then((response)=>{ // console.log(response.data) setWatchLater(response.data) }) } The…
1
vote
1 answer

material-table in react does not display data in onRowAdd but but the state is changed

This is my onRowAdd function, before adding the value in the table I'm testing if the values provided are true or not. The Issue is that when input values are true, new data newData is added into the state, but the material table does not display…
1
vote
1 answer

Javascript Promisification, why use "call"?

I want to understand why in the below example, the "call" method was used. loadScript is a function that appends a script tag to a document, and has an optional callback function. promisify returns a wrapper function that in turn returns a promise,…
Elbasel
  • 11
  • 4
1
vote
2 answers

Upload status for every file in JS

I'm trying to build input to upload multiple files and get response from server to update a UI. I built something like this using jQuery: function UploadFile(file) { return new Promise((resolve) => { $.ajax({ url: "/api/admin/upload", …
pepeD
  • 155
  • 16
1
vote
0 answers

check authenticated user in ProtectedRouter component in react using react router v6

my app.jsx import axios from "axios"; import { createContext, useState } from "react"; import { BrowserRouter, Routes, Route } from "react-router-dom"; import NavBar from "./components/Navbar"; import ProtectedRoute from…
z41dth3c0d3r
  • 120
  • 8
1
vote
2 answers

How do I wait for a promise to finish inside a loop? (without using async-await)

The below code waits only for the 1st iteration of the for loop. If I use async-await, it works fine. So where am I going wrong here? function wait(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)) } function…
Tony Mike
  • 11
  • 2
1
vote
2 answers

Firebase resolve Promise

I'm starting in the world of promises and there is one thing I can't understand. I am trying to make a system that returns a document from a Firebase collection by its ID. For this I use 2 functions const getProductDataById = async(idProduct)=> { …
Marcvilap
  • 23
  • 3
1
vote
0 answers

How to implement breakpoint continuation when multiple fetch API work at the same time

I need to request a large file in pieces and construct a new readablestream from the response. At first, I only requested one piece of data at a time, and on this basis, I realized the breakpoint continuation to deal with the instability of the…