Questions tagged [promise]

Promises are a tactic for deferred computing, suitable for several styles of concurrency: thread and event loop concurrency for local computation, and both synchronous and asynchronous remote messaging. A promise represents the eventual result of an asynchronous operation. The primary way of working with promises is through a method which registers transformations from the promise's eventual value or failure reason to a new promise.

In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete.

Promises are a common construct in with new built in language support. There are several popular implementations of the concept such as and . However, promises are not unique in JavaScript and similar patterns exist in many languages. Popular implementations exist in , , , , , , and most other languages. Some languages provide native language support for the construct.

Recurring questions:

Reading material:

Popular Implementations:

22514 questions
5
votes
2 answers

Is it possible to reject each Promise in Promise.allSettled if it takes more than 5 seconds to resolve?

I have a Promise.allSettled which i use to resolve data in the database. I have an array of Promises which I run through the Promise.allSettled, then I only use the resolved ones. Is it possible to set a timeout inside the Promise.allSettled, so…
TheStranger
  • 1,387
  • 1
  • 13
  • 35
5
votes
2 answers

How would you display a promise object's state and value when overriding console.log

I'm attempting to display the console.log output in a div. I'm doing this by overriding the console.log function When I use the original console.log, a promise displays, in the console as (see 1. in code below): Promise { : "fulfilled",…
Lee
  • 29,398
  • 28
  • 117
  • 170
5
votes
1 answer

Cypress.io make async request in custom login command

I want to configure a custom login command in which I have to make a signIn call which returns a promise. commands.js: Cypress.Commands.add("login", () => { AuthLib.signIn(username, password).then((data) => { cy.setLocalStorage("accessToken",…
xtra
  • 1,957
  • 4
  • 22
  • 40
5
votes
2 answers

Javascript: Awaiting resolved promise

I would like to know, if awaiting a resolved promise, will lead to a synchronous code execution or may lead to asynchronous one. I made this little snippet to check on browsers : const promise = new Promise((resolve) => { console.log('exec…
Poyoman
  • 1,652
  • 1
  • 20
  • 28
5
votes
1 answer

Async promise executor functions

I have a function that returns a Promise like this: async function processFolder(folder) { return new Promise(async (res) => { const table = {}; const list = await getHTMLlist(folder); if (list.length === 0) res(table); …
Plastic
  • 9,874
  • 6
  • 32
  • 53
5
votes
2 answers

Subclassing the Promise built-in using extends

I want to add a cancel method to a subclass of the Promise built-in. Why does this not work? class CancellablePromise extends Promise { constructor(executor) { let cancel = null super((resolve,reject) => { cancel =…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
5
votes
2 answers

Possible to make an event handler wait until async / Promise-based code is done?

I am using the excellent Papa Parse library in nodejs mode, to stream a large (500 MB) CSV file of over 1 million rows, into a slow persistence API, that can only take one request at a time. The persistence API is based on Promises, but from Papa…
blitter
  • 347
  • 5
  • 21
5
votes
1 answer

Empty then on promise

During work, I stumbled upon this line inside our codebase (designed to run in the browser). Is there any effect in this line? It seems unnecessary to me, but before removing it, I want to be absolutely sure that I am not overlooking some quirky…
Erik Brendel
  • 683
  • 9
  • 23
5
votes
4 answers

How to use Promise.all to handle thousands of request

In my React app I have a component that send request to an online service that is capable to handle 50 requests max. I got a new request now to execute 7000 MAC’s. function App() { const [data, setData] = useState([]); useEffect(() => { const…
angus
  • 3,210
  • 10
  • 41
  • 71
5
votes
0 answers

Type 'Promise' is missing the following properties from type 'ReactElement

I have a compilation issue when trying to render ClientDetails component passing a list of Client in props: I got this error message: Type '{ (): Promise; propTypes: {}; }' is not assignable to type 'ComponentClass |…
Mselmi Ali
  • 1,139
  • 2
  • 18
  • 28
5
votes
2 answers

Getting error TypeError: Promise.any is not a function

I am learning Promise.any from the following site. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any The IDE does not show any error, but while running using yarn command , I am getting the following…
Deba
  • 859
  • 5
  • 9
  • 21
5
votes
2 answers

React - useEffect with async setState causing additional re-renders

I have a React hook here export const useConfigDetails = (resourceName: string) => { const [isLoading, setLoading] = React.useState(true); const [error, setError] = React.useState(undefined); const [allEnvDetails,…
Christie Chen
  • 185
  • 1
  • 5
  • 15
5
votes
1 answer

How Can I Unwrap an Array of Promises within a Chain of Array Methods?

I have a chain of several maps, one of which needs to perform a database operation for each array element, so I'm using async await. const resultsAsPromises = arr .map(syncDouble) .map(asyncMapper) This isn't a problem if it is the last item in…
1252748
  • 14,597
  • 32
  • 109
  • 229
5
votes
1 answer

Typescript throws an error when calling Promise.all with an array of promises

I have a problem with Promises in Typescript. I'm trying to call Promise.all with an array of promises but instead, I get No overload matches this call. The last overload gave the following error. Argument of type '(Promise | Promise)[]' is not…
Dominik
  • 75
  • 2
  • 6
5
votes
2 answers

Handle Promise Catches in Typescript

I have a promise based API service that requests data from my backend. It also comes with it's own error catch, so I don't have to write it everywhere. When it's written like this: BackendService.ts ... getTasks() { return…
Vincent
  • 137
  • 2
  • 15
1 2 3
99
100