Questions tagged as 'promises'

2
answers

What are promises in javascript?

I was searching about callback in JavaScript when I found this question:    How to really learn how to use promises in> (promises) in javascript? But after all: What are promises? What are they for?
asked by 24.03.2016 / 17:29
3
answers

Difference between promise and callback

I would like to understand the benefits of using Promise a little better! Today I use callback function. Ex: function a(callback) { $.ajax({ ... }) .done(function(data){ callback(data) }) .fail(function(data){...
asked by 30.11.2016 / 19:40
1
answer

How does ES7 async / await work?

ES7 allows you to use a new syntax to work with Promises known as async / await functions. How can I use these functions and how are they compared to functions that use Promises to process data sequences and in parallel?     
asked by 24.08.2016 / 00:41
1
answer

Difference between promise.then (sucess, error) and promise.then () .catch ()?

Hello, I would like to clarify the difference and when to use each of the promising treatment templates: obj.promessa( parametro ).then( function ( resposta ) { console.log("Resposta: " + resposta); }, function ( erro ) { console.lo...
asked by 24.05.2017 / 21:59
4
answers

How to make a LOOP run according to the return of a 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 = function(obj) { $http.get(url).then(...
asked by 29.06.2016 / 14:51
1
answer

How to execute a callback at the end of a $ http promise, to work on success or not?

In the Angle, I am executing a call HTTP through $http.get , and when this request ends, I change the value of a variable through callback in then : $scope.carregando = true; $http.get('/users/list').then(function (response...
asked by 07.11.2017 / 19:03
0
answers

How to return a Promise from an AngularFireObject using @ angular / fire in Angular (v6 +)

Hello, I'm working on an Angular project where I need to return a Promise on a given service. My code looks like this: import { Injectable } from '@angular/core'; import { AngularFireDatabase } from '@angular/fire/database'; @Injectable...
asked by 30.10.2018 / 14:43
1
answer

How the Promises works in Angularjs

I'm having a bit of trouble understanding Angularjs Promises I have the following code: function validateUser(name, pw) { var status = ''; var data = {login: name, senha: pw, plataforma: 'APP'}; $http.post('http://localhost:8100/l...
asked by 14.10.2016 / 16:16
1
answer

Order of execution in a Promise

I have the following code: const execute = function() { return new Promise((resolve, reject) => { setTimeout(() => { console.info('Iniciou'); resolve('Executando'); console.info...
asked by 15.11.2018 / 03:26
1
answer

NodeJs api with promisses

I'm developing an API in TypeScript with NodeJS and MariaDB; when I do an operation with the bank, right below I have a if to check if an error has occurred. productDao.save({name:"Notebook Dell", price:"5000"}, function(err, res){ if(err...
asked by 29.06.2017 / 19:46