How long can a promise remain on hold?

I use Promises in an Angular (4) project, and I have a question about them that I cannot find the answer to in the docs.

When I create Promise, I basically wait for the async response from the service / member. But how long should I expect this promise to remain pending? Is there any mechanism that will stop it after some time? How reliable is this expectation / expectation concept?

Suppose that I need to get some data from the employment service that can respond even after a few minutes of waiting, maybe more, regardless of whether the calculation of the response is a resource-intensive process or this service is connected to another one that responds very slowly. Is there anything on the client side that somehow breaks my promise and determines / forces to create another one to request my data again?

Someone suggested upgrading to Observables, and I will do it, but for now I want to continue using Promises, at least for some areas of the code.

Tks a lot

+4
source share
2 answers

A Promise , .

Promise, -,

let wrappingPromise = new Promise((resolve, reject) => {
  var error = false;
  setTimeout(function(){
    reject("some error"); 
  }, 3000);
  this.http.get(...).toPromise().then(res => {
    if(!error) {
      resolve(res.json);
    }
  });
}); 

. . , , . , API.

+2

new Promise(() => {}) , , callback .

- , , . . .

API, , .

promises

promises, API. Promise, API . .

+2

Source: https://habr.com/ru/post/1677364/


All Articles