Most voted "promises" questions
An object preserves the promise that the function it generated will sometime in the future end and return you a response. It can be a positive or negative response. The Promise can be passed to other functions or returned.
Learn more…133 questions
Sort by count of
-
43
votes3
answers9745
viewsWhat are Javascript Promises (promises)?
I was researching about callback in Javascript when I found this question: How to really learn to use Promises (promises) in javascript? But after all : What are promises? What are they for?…
-
13
votes1
answer545
viewsHow does ES7 async/await work?
ES7 allows you to use a new syntax to work with Promises known as async/await functions. How I can use these functions and how they are compared to functions that use Promises to process sequential…
javascript asynchronous ecmascript-6 promises async-awaitasked 8 years, 3 months ago Gabriel Gartz 5,624 -
13
votes3
answers4398
viewsDifference between Promise and callback
I would like to understand a little better the advantages of using Promise! today I use callback function. Ex: function a(callback) { $.ajax({ ... }) .done(function(data){ callback(data) })…
-
11
votes2
answers388
viewsAsynchronous return of some Apis
Why the return of some Apis are exactly the result we want (for example, a JSON) and some others return an object full of functions and objects? Example API that directly returns the result I want:…
-
11
votes1
answer4239
viewsWhat are the differences between Promise.all() and Promise.allSettled()?
I’m running some tests with Promises and I found that there are two ways to get the result of a set of protocols: using Promise.all(): async searchSegmentsInformations(segmentId) { try { const…
-
10
votes1
answer7242
viewsDifference between Promise.then( sucess, error ) and Promise.then() . catch()?
Hello, I would like to clarify the difference and when to use each of the models of handling promises: obj.promessa( parametro ).then( function ( resposta ) { console.log("Resposta: " + resposta);…
-
10
votes3
answers195
viewsWhy do I need to spend two then on AJAX requests made with the fetch API?
In the example of the following request: fetch("https://viacep.com.br/ws/01001000/json/") .then(resposta => resposta.json()) .then(json => console.log(json)); In the first then should not…
-
8
votes1
answer116
viewsResolve/Reject play role in javascript?
As mentioned in the title, the resolve and Reject of a Promise already "make paper" of Return or yes (depending on the occasion) I need to use the Return? Explaining with code, I could do these two…
-
8
votes1
answer385
viewsWould "Promise.all" (and other similar functions) be an example of Javascript parallelism?
In Javascript, we have the Promise.all, that solves an array of promises in a single Promise. This process is apparently parallel, since the promises are resolved at the same time, and not in a…
-
7
votes1
answer2366
viewsHow to assign the result of a Promise to a variable?
Even reading this one another question of the site, I still do not understand why I can not withdraw a value from within a Promise. How do I do that kind of assignment? The idea is to execute…
-
7
votes2
answers641
viewsWhen "Return" is different from "Return await" in an asynchronous function in Javascript?
I was doing a review of MR and saw a test similar to this: it('...', async () => { return await new Promise((resolve, reject) => { request(app.getHttpServer()) .get('...') .send({ /* ... */ })…
-
7
votes1
answer118
viewsHow to adapt a function that only accepts callback to the promise interface in Javascript?
I’m using an external library function to acquire the token of a user, it is the following: export default function GetGraphToken( email: string, password: string, callback: (graphClient: Client,…
javascript typescript asynchronous promises callbackasked 3 years, 11 months ago Matheus Wallace 73 -
6
votes1
answer115
viewsWhy should we interrupt the Promises current in recursive functions in Javascript?
I will exemplify with codes. I have an asynchronous function called delay which receives a time in seconds and which returns a Promise. It serves to provide a waiting time in seconds: // padrão de 1…
-
5
votes1
answer66
viewsHow to return a Promise from an Angularfireobject using @angular/fire in Angular(V6+)
Hello, I’m working on a project in Angular where I need to return a Promisein a particular service. My code is like this: import { Injectable } from '@angular/core'; import { AngularFireDatabase }…
-
5
votes1
answer115
viewsAccess variable of a Function in another Function
I’m starting in Javascript and I’m having the following difficulty, I need to take a variable and access it in another Function. I have created a variable without specifying anything making it…
-
5
votes1
answer375
viewsHow to cancel/interrupt a request made with Axios?
Generally, I usually make some AJAX calls with the library Axios. Those days I needed a resource, where I could interrupt a certain request already started, but did not know how to do. Is there any…
-
4
votes2
answers110
viewsIs it possible to use Async Generators with the ES5 syntax?
For example, the code below that creates a async Generator: async function* iterate() { yield 1; yield 2; yield 3; return null; } Could be used with the syntax for await...of: for await (const…
-
4
votes1
answer73
viewsWhat is the purpose of the Promises Timers API on Node.js?
Recently, in the version V16.0.0 of Node.js, added the Promises Timers API, and from what I understand, it’s about alter the behavior of standard timers (setTimeout, setImmediate, etc...). These…
-
3
votes1
answer328
viewsWhat do these mysterious double brackets mean in javascript?
Say I raise a Promise to javascript: var a = new Promise(function(success, error){ { sucess("Sucesso!"); }) My variable a receives the following properties: Promise {[[PromiseStatus]]: "resolved",…
-
3
votes4
answers1025
viewsHow to make a LOOP run according to the return of a Promise (promise)?
How can I make my loop wait for the return of a Promise? Let’s say I have the following code: for (var i = 0; i < 10; i ++) { // algumalógica fazAlgumaCoisa(array[i]); } var fazAlgumaCoisa =…
-
3
votes1
answer510
viewsHow to run a callback at the end of a $http file, whether it works or not?
At Angular, I’m running a call HTTP through the $http.get and, when this request ends, I change the value of a variable through the callback in the then: $scope.carregando = true;…
-
3
votes1
answer201
viewsHow to resolve or reject a Promise (native) in Javascript outside of your scope?
Most of the implementations I see of Promises (promises) in frameworks Javascript treats the use of Promises in a way that it is possible to access the functions responsible for rejection and…
-
3
votes1
answer210
viewsReturn a function to be executed - Typescript
I’m in a situation where I would like to generate an engine that runs an async function and that runs a successful callback on Ry and a catch error, and the responsibility of these callbacks is to…
-
3
votes1
answer1084
viewsReturn value of Promise
I have the following code: const retorno_valores = [] result.forEach( value => { var reader = getReader(conn, 10) retorno_valores.push({reader}) }); const getReader= async (conn, cdReader)=>{…
-
3
votes1
answer104
viewsHow to use Promises with button in Javascript?
Hello, I’m a beginner in Javascript and I wanted to create a code where we write something in the input and when clicking a button we would call a Promise. It would try to make a request on the site…
-
3
votes1
answer119
viewsProblem using map with async and await in Javascript
I have a code block where an array type variable is defined and within a function map, I push some values to that array. Inside the map, I can print the array with the filled objects. However,…
-
2
votes0
answers108
viewsAre promises supposed to replace callback functions?
As Promises replace the functions of callback? Or the Promises are used only in asynchronous functions?
-
2
votes1
answer55
viewsUse variable from one class to another
I have the following method: this.retorno.then(function(result){ let a = result[0].infos.inProgress; var cards = []; a.forEach(b => { let card = new Card(b.name, b.type, b.date, b.id);…
-
2
votes1
answer102
viewsUsing Promises and Deffered in everyday life
I’m studying about these items and I’m having doubts about how to apply them to my projects. I currently use callback for everything but the structure of the code is tense.. and on the Internet I…
-
2
votes1
answer1714
viewsHow Promises works in Angularjs
I’m having a little trouble understanding the workings of Promises of Angularjs. I have the following code: function validateUser(name, pw) { var status = ''; var data = {login: name, senha: pw,…
-
2
votes1
answer421
viewsPromise return
Considering the example below: function retornaValor (){ return promiseQueveioDeAlgumaLib.then( function(oQueQueroRetornar){ return { sucesso: true, data : oQueQueroRetornar } },…
-
2
votes1
answer308
viewsHow to recall the function without losing the Precedent?
I’m still beginner in Node.Js, and do not know how to do this operation. In the code below to realize that the function readSubscriptions() is called right after function login(). But if there is an…
-
2
votes2
answers739
viewsHow to ensure that a ngOnInit-dependent function is executed after it?
I have a class that when booting retrieves data from a service and popular one of its attributes, which is a array. This class has a function that sorts this array, filter and return the result.…
-
2
votes1
answer104
viewsNodejs api with Promisses
I am developing an API in Typescript with Nodejs and Mariadb; when I do an operation with the bank, below I have a if to check if an error has occurred. productDao.save({name:"Notebook Dell",…
-
2
votes2
answers636
viewsWait for ajax response before moving to the loop
How could I make the following code work? On the Sleep.php page I have 2 seconds waiting only for the test. I need the next for run only after the full execution of the function corrige. I tried to…
-
2
votes1
answer452
viewsPromise not returning value
My request is returning this to me: data: Promise Opening Chrome Developer Tools I see this: data: Promise __proto__:Promise [[PromiseStatus]]:"resolved" [[PromiseValue]]:"24/01/2016" Using Axios,…
-
2
votes1
answer170
viewsNode js, promises, callback
I need to run certain updates and delete within a query return in my controller. but only the last function is executed I don’t think I understand how to use promises. api.adMaster = function (req,…
-
2
votes0
answers457
viewsHow do I process a JSON in the event of a request-Promise failure?
I have 2 Microservices, one in Nodejs and the other in Spring. Nodejs contains the domain of events (parties, birthdays etc) and Java the domain of users. When viewing Nodejs event endpoints, I also…
-
2
votes1
answer80
viewsMake code that uses Promises work also on older browsers
I recently asked that question: Wait for the variable to be completed The moderator Sergio helped me with the issue, but I’m still having problems with compatibility with old browsers. There is a…
-
2
votes2
answers891
viewsAssign the return of a function that returns from a Promise
I am exporting a function to another file that is as a Webpack-simple + Vuejs component. That’s the function of the file api-user.js: export function getUsers () { axios.post('/api/get_list',{})…
-
2
votes2
answers3881
viewsHow do I return a Promise value in Javascript?
Well I’m facing the following problem, I’m contributing to a Mozilla extension, but most browser Apis use Preses to do things, only the problem is that I don’t know much. So I would really like to…
-
2
votes2
answers1162
viewsIonic - wait for http get return
Edit: solution in the third answer. I’m trying to do a login function for a project on Ionic 2. This function checks if the user is registered in the database through the php server and returns the…
-
2
votes1
answer444
viewsHow to make a chained file with pure Javascript?
How to make a dazed call with Javascript native Promise? I mean, I would like the sentence below to be executed one after the other and I would like to know when that sequence of Promises is…
-
2
votes1
answer47
viewsExecution order on a Promise
I have the following code: const execute = function() { return new Promise((resolve, reject) => { setTimeout(() => { console.info('Iniciou'); resolve('Executando'); console.info('Finalizou');…
-
2
votes1
answer118
viewsHow to return a Promise from the resolution of others?
I’m relatively new to this Promises, despite having used them numerous times, especially in AJAX requests. I’m building a front-end application that runs on Sharepoint and, to get a lot of…
javascript internet-explorer promises ecmascript-5 ecmascript-6asked 5 years, 1 month ago J. L. Muller 555 -
2
votes1
answer25
viewsError on a JS Promise
I have the following code: var age = parseInt(prompt('Digite sua idade: ')); function verificar(age){ return new Promise(function(resolve,reject){ if(age > 18){ resolve(console.log('DEU CERTO'))…
-
2
votes2
answers78
viewsUsing Promise Javascript
Hello, I have a requisition GET in Jquery, to load a page HTML; and if the page does not exist, then displays in the container a <div>erro 404</div. The Jquery request works well. Jquery…
-
2
votes1
answer100
viewsHow to make a upload message while a Promisse loads?
I created a js file with the following code: function buscarRepos(){ lista.innerHTML = ''; var nomeUser = document.querySelector('div#app input').value; var resultado = minhaPromise(nomeUser)…
-
2
votes1
answer28
viewsPromise does not execute . then()
Good morning, I need help with my Password, when recording my information in indexDB I am using . then to write on the console, but this . then is not fired. I noticed that my Promise gets pending…
-
2
votes1
answer57
viewsDoes Settimeout run in parallel on Node.js?
I’m studying the concepts of asymchronism, I know that Node.js is single-threaded and that for some types of task he delegates the same to the libuv (which has 4 threads by default) and others for…